Hello!
I have a simple question here:
How does an IF statement react on bitwise commands like this:
a = 0x07;
b = 0x02;
if(a&b)
DoSomething();
Is the IF statement TRUE or FALSE?
Tnx
/D
:confused:
Printable View
Hello!
I have a simple question here:
How does an IF statement react on bitwise commands like this:
a = 0x07;
b = 0x02;
if(a&b)
DoSomething();
Is the IF statement TRUE or FALSE?
Tnx
/D
:confused:
this statement would be true:
since 0x7 = 0111 bin
and 0x2 = 0010 bin
-> the result of the & operation is 0x2
and this is not 0, so its True :)
I'd say it returns true.
0x07 in binary is 111 and 0x02 is 010, so when it does the math
which gives 2 as a result anyway.Code:111
& 010
----------
010
EDIT: Damn you IceBall, you beat me!
There is no 'IF' in C. Maybe you meant 'if'.Quote:
Originally Posted by DeeAitch
There is no 'command' in C, but statements, operators, expressions, functions...
A C expression returns 0 or 1, not TRUE/FALSE.
Simple question of boolean logic. What is the AND truth table, what is the result of 0x07 AND 0x02 ?
Shake your brain, it helps...Code:a = 0000 0111
b = 0000 0010
a AND b = ???? ????