Bit Manipulation

Power of 2

  • n > 0 && !(n & (n-1))

Power of 3

  • fmod(log10(n)/log10(3), 1)==0

Power of 4

  • Check is power of 2
  • And num-1 is divisible by 3
  • !(num & (num - 1)) && (num - 1) % 3 == 0

Technique 1: Find number of 1 bit

We don't have to loop through the entire binary bits, this can be easily found out using n &= n-1

  • Hamming Distance
  • Number of Bits

results matching ""

    No results matching ""