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
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
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!
Last edited by -=SoKrA=-; 12-28-2004 at 04:47 AM.
SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
I say what I say, I mean what I mean.
IDE: emacs + make + gcc and proud of it.
There is no 'IF' in C. Maybe you meant 'if'.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 = ???? ????
Emmanuel Delahaye
"C is a sharp tool"