Go Down

Topic: weird comparison (Read 435 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.


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy