// Left shift ---> Multiplying by 2 int x = 6; x <<= 1; cout << x; // 12 -------------------------------------------------------------------------------------------------- //Right shift ---> Divide by 2 int x = 12; x >>= 1; cout << x; // 6 -------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------- // Checking if given 32 bit integer is power of 2 // if true return 1 else return 0 int isPowerof2(int x) { return (x && !(x & x-1)); } -------------------------------------------------------------------------------------------------- // Find log base 2 of 32 bit integer // log2(8)=3 when 2^3 = 8 int log2(int x) { int res = 0; while (x >>= 1) res++; return res; } --------------------------------------------------------------------------------------------------