Hi ,
Could you please explane to me the statment " b&01"
b=4=100 (in binary)
why 100&01 it's 0? ( and not 100)
Code:int b=4; if (b&01) { //do somthing }
Hi ,
Could you please explane to me the statment " b&01"
b=4=100 (in binary)
why 100&01 it's 0? ( and not 100)
Code:int b=4; if (b&01) { //do somthing }
Here's the the truth table for &:
& is a bit operator thus you have to combine the equivalent "digits":Code:a | b | a & b 1 | 1 | 1 1 | 0 | 0 0 | 1 | 0 0 | 0 | 0
And numbers with a leading 0 are treated as octal values in C (not relevant here, but probably in other problems).Code:1 0 0 & 0 1 ----- 0 0 0
Bye, Andreas
Hi Andreas
Q -1 what about regarding the 1 degit in red?
With what do I multipole the red 1 ?
1 0 0
&
0 1
Q -2
10110 ---------> ( 22 desimal)
&
000 ---------> ~( 7 desimal)
-------
10000 ---------> (16 desimal)
22&~7=16 in the example the 10 left digits are remain as they are , could you please explane?
You fill up the left side with zeros. It's the same principle with decimal numbers:
is the same asCode:1 2 3 + 4 ----- 1 2 7
Bye, AndreasCode:1 2 3 + 0 0 4 ----- 1 2 7
Last edited by AndiPersti; 04-22-2013 at 10:52 AM.
~7 does not equal zero.22&~7=16 in the example the 10 left digits are remain as they are , could you please explane?
It gives a value for which all but the last 3 bits are ones.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"