Bool

Hi guys some questions to bool:

1
2
  Z = !((10 < 20) ^ (5 % 3)) 
  Z = ((5 < 10) - (3 & 1)) == 0;


so the first one: I understand that the result will be a NOR Statement? So 10<20 would give a true and what does 5%3 give?

2nd line : 5<10 would give true but what does 3&1 give or even mean?

Thanks again
Last edited on
What type is Z? You haven't shown it's declaration.

The first one is NOT XOR, which is not the same as NOR.
5 % 3 is a modulo (remainder) operation. The remainder of 5 / 3 is 2. So (5 % 3) is also true.
^ is an XOR operation. true XOR true is false. ! (false) is of course true.

& is a bitwise AND operation 3 & 1 is 1. That leaves us with true - 1 which is a mix of types. Since true can be promoted to an int we have 1 - 1, which is 0. 0 == 0 is true, so Z is true.
Last edited on
operation 3 & 1 is 1

thanks for the reply. But I dont understand why 3&1 is 1?
Last edited on
This is a bitwise AND operation. The bits of the two numbers are ANDed.

3 = 0011
1 = 0001
------------
R = 0001

The least significant bit is the only bit set in both operands and therefore the only bit set in the result.
Topic archived. No new replies allowed.