# I don't understand this, help? ((boolean))

• 07-03-2005
Raeliean
I don't understand this, help? ((boolean))
WTH does this mean?

A. !( 1 || 0 ) ANSWER: 0
B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)
C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)

The way I read it is..
A. not 1 or 0, false.
B. not 1 or 1 and 0, false.
C. not (1 or 0) and 0, true.

I don't understand it at ALL, what makes them come out true or false or am I just reading it wrong? Can I please get some help?
• 07-03-2005
Hunter2
Read it as a mathematical expression, not as an english phrase. Also remember, 1 means true and 0 means false.

A. (true or false), take the inverse
B. [true or (true and false)], take the inverse
C. [(true or false) and false], take the inverse.

Where 'take the inverse' means, true->false and false->true.

You just need to take it in order of operation, where each expression (left <operator> right) evaluates to either true or false. For example:

(true or false) -> true (an 'or' operation is true if either 'left' or 'right' is true)
(true and false) -> false (an 'and' operation is false if either 'left' or 'right' is false)
(true or false) or (true and false) -> (true) or (false) -> true
• 07-03-2005
xErath
In C 0 represents boolean value false. Any other non-zero value is boolean true. Knowing this, and assuming you know what a logic OR and AND is.. good luck.
• 07-03-2005
sean
They way you put it, it sounds like you're not familiar with boolean logic and the different functions, so I'll explain those.

Replace ALL the ones and zeros with true and false, respectively. In logical statements, think of ! as "the opposite of". So let's solve each statement without the !, and then just take the opposite of it.

The OR function will output true if either operand is true. There's also some variations of OR which don't concern you now.

So in the first stamment we have the OR function with true and false as operands. At least one of the operands is true, so OR outputs true. Take the opposite of this: false.

The AND function will output true if an only if both operands are true. In this case at least, AND is evaluated before OR, so lets evaluate it first. AND is given true and true as operands. Obviously, it should output true. So now we have that result, true, and a false as the two operands for the OR function. Again, at least one operand is true, so it outputs true. Don't forget to take the opposite of this, and we get false.

Then parentheses are interpreted first in every situation I'm aware of in mathematics and programming. Inside the parentheses, we have a true and a flase going to an OR function. Again, this situation will output true. So now we have that result, true, and a false in an AND function. Only one operand is true, so it will output false. Take the opposite, and we have true.

I hope this makes it clearer for you. Even if you don't see the purpose to this kind of logic yet, just learn the behavior of each function, and eventually you'll get to use it in a practical application - I use it all the time now, actually.
• 07-03-2005
Raeliean
Thank you all for the help, I think I got it now.
• 07-03-2005
Dae
A. !( 1 || 0 ) ANSWER: 0
B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)
C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)

True = 1;
False = 0;

A. opposite (!) of what (1 OR (||) 0) resolves to
- If its in brackets (parenthesis), do that part first, (1 or 0), well.. it returns true (1) if either are 1, so its returned true (correct) which is 1. So now you have !1, the opposite of 1 is: 0. So the answer is 0.

B. opposite of (also called NOT) (1 OR 1 AND 0)
- The symbol that is processed first, || or &&, will effect the outcome, the list of symbols says && is processed first, then || (on that site you read this from). As B says "AND is evaluated before OR".
- So 1 && 0 returns false (its only true if they are both true), which leaves you with (1 || 0), which returns true: 1, which leaves you with !1, the opposite of 1 is 0. So the answer is 0.

C. NOT ((1 OR 0) AND 0)
- The brackets first: (1 OR 0) which returns true: 1, and then leaving you with 1 && 0, which returns false: 0, which leaves you with !0, and that resolves to 1. So the answer is 1.

I find it impossible to explain this better than the tutorial does. But thats just how I'd break it down if it helps.