Pages: [1]   Go Down
Author Topic: weird comparison  (Read 346 times)
0 Members and 1 Guest are viewing this topic.
jordan
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

France
Offline Offline
Edison Member
*
Karma: 38
Posts: 1012
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is no comparison, it is bit shifting and masking smiley-grin
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8856
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
if (data & (1<<i))
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26346
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This is no comparison, it is bit shifting and masking
..apart from the "greater than zero".
That's a comparison.
Logged

"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.

jordan
Offline Offline
Jr. Member
**
Karma: 0
Posts: 56
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanx all
Logged

Pages: [1]   Go Up
Jump to: