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

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -