How to double a variable with bitwise shift left in C++

1 Answer

0 votes
#include <iostream>

int main() {
    int num = 8; 
    
    num = num << 1; // Left shift by 1 to double the value

    std::cout << num << std::endl;

    return 0;
}



/*
run:

16

*/

 



answered Mar 9, 2025 by avibootz

Related questions

1 answer 215 views
1 answer 200 views
1 answer 190 views
1 answer 202 views
1 answer 186 views
1 answer 210 views
1 answer 200 views
...