Smallest perfect power of 2 greater than n ( without using arithmetic operators ) | Function to find smallest perfect power of 2 greater than n ; To store perfect power of 2 ; bitwise left shift by 1 ; bitwise right shift by 1 ; Required perfect power of 2 ; Driver program to test above
function perfectPowerOf2 ( n ) { let per_pow = 1 ; while ( n > 0 ) { per_pow = per_pow << 1 ; n = n >> 1 ; } return per_pow ; } let n = 128 ; document . write ( " " + n + " " + perfectPowerOf2 ( n ) ) ;