Find position of the only set bit

The main principle of this code logic is one by one right shift the set bit of given number ‘n’ until ‘n’ becomes 0. Count how many times we shifted to make ‘n’ zero. The final count is position of the set bit. This is Simple and efficient way because bitwise operator take shorter time to execute than arithmetic operator.

 

 

 

Suggested Reading

  1. Count number of 1s in given binary number
  2. Write a Macro’s Set,clear and toggle n’th bit using bit wise operators?
  3. Write a c program to implement XOR functionality with out using XOR(^) operator

If you like this Article, then don’t forget to Click on Social likes buttons.