I think my last post was confusing because I didn't ask the right question.
I have a 64 bit unsigned integer. I want to find the position of the first (or the last) bit set to 1 without a loop.
I'm using this code:
int position(uint64 number){
for(int i=0; i<64; i++)
if ( (((uint64) 0x01) << i) & number)
return i;
return -1; //All the bits are 0
}
I know that there is a short method to find it using a formula but I have not found it.
I have a 64 bit unsigned integer. I want to find the position of the first (or the last) bit set to 1 without a loop.
I'm using this code:
int position(uint64 number){
for(int i=0; i<64; i++)
if ( (((uint64) 0x01) << i) & number)
return i;
return -1; //All the bits are 0
}
I know that there is a short method to find it using a formula but I have not found it.