Problems with retrieving forst three bits of a number
Hey,I am trying to retrieve the first three bits of a number. The code that I am using should work but it isn't giving me the correct result when trying certain numbers. Below is the code I am using:
unsigned short num1, num2 = 0;
unsigned short num = 65535// binary 111111111111111
num1 = num && 0x07;// gives me 1 but should give 7(111)
num2 = num >>3;//gives me 8191, which is correct
Can anyone tell me why I am not getting the first three correct bits(111)?
Thanks In Advance
num1 = num & 0x07 ;
&& is the logical and.
Topic archived. No new replies allowed.