bitwise operators - How to get position of right most set bit in C -


int = 12; 

for eg: binary of 12 1100 answer should 3 3rd bit right set.

i want position of last set bit of a. can tell me how can so.

note : want position only, here don't want set or reset bit. not duplicate of question on stackoverflow.

try this

int set_bit = n ^ (n&(n-1)); 

Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Restarting Supervisor and effect on FlaskSocketIO -

php - Mongodb connectivity error -