Need Help Urgent - Bit level operation
Hi I have the following requirement:
I have to find the position of the higher order bit for a given number. I am achiving it by the following method.
for (int key = 0; key<32; key++)
result = ((given_number & 0x80000000) == 0) ? 0 : 1;
This works fine when the given_value is of type int.
For long it doesnt work at all.
Ex. if given value is 1048576, I get the posiotn of 1 to be 11.
when i print this, 00000000000100000000000000000000
But if i initiliaze 1048576 as long, it doesnt work.
When i print this 00000000000111111111111111111111