You can also use bitshift since the base is 2

I did it in rust but in c++ the shift operator should be the same:

println!("2 to the power of 24 is: {}", 2u32 << 23);

I’m using 23 as the shift number since every increment of the position of the bit corresponds to a multiplication. 2u32 << 1 would already be 4 = 2^2

Oh this is really clever. I just did the standard/boring approach of i32.pow()

Privacy & Terms