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 102 views
1 answer 91 views
1 answer 95 views
1 answer 93 views
1 answer 88 views
1 answer 81 views
1 answer 96 views
...