Go Down

Topic: weird comparison (Read 384 times) previous topic - next topic

TTU.ABD

is this statment [  if((data>>i) & 0x0001 >0)  ] same as [ if((data>i) && 0x0001 >0) ] ?

guix

This is no comparison, it is bit shifting and masking :D

johnwasser


is this statment [  if((data>>i) & 0x0001 >0)  ] same as [ if((data>i) && 0x0001 >0) ] ?


No.

>> is the Shift Right operator and & is the bitwise AND operator.

It's testing bit 'i' of data, equivalent to:

Code: [Select]
if (data & (1<<i))
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

AWOL

Quote
This is no comparison, it is bit shifting and masking
..apart from the "greater than zero".
That's a comparison.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

TTU.ABD


Go Up