Boolean Operators

Hi all,

Just a general question, I'm a beginner working through some tutorials and I've been looking at boolean operators.

I understand the basics of the NOT, AND and OR operators. I just don't understand how they work together. I might be missing something obvious but I just needed some help. These examples are given in the tutorials.

A. !( 1 || 0 ) ANSWER: 0
B. !( 1 || 1 && 0 ) ANSWER: 0
C. !( ( 1 || 0 ) && 0 ) ANSWER: 1

I just don't understand what's being compared? How are the answers being calculated? Any help will be appreciated.

Thanks in advance.
How are the answers being calculated?

If the operation is only using the operators NOT (!), AND (&&), and OR(||), then essentially you look for the operations in brackets first and work your way out.

e.g.

1
2
3
4
C = !( (1 || 0 ) && 0 )
C = ! ( 1 && 0 ) //true OR false == true
C = ! ( 0 ) //true And false == false
C = 1 //NOT false == true 
1
2
3
4
5
6
7
C = !( (1 || 0 ) && 0 )

C = ! ( 1 || 0 )  //true OR false == because the 1's there it's true.

C = ! ( && 0 ) //true And false == there aren't two inputs so it's false?

C = 1 //NOT false == because it's not 0, it's therefore true?  


So is it broken up like that, As in you do the OR bit first, then you do the AND from the end, and then you're left with the NOT 1?

Then altogether there is 2 trues and 1 false, does this make the overall outcome true, which is why the answer is one?

Might take a bit longer for me to get it. Sorry if i'm just being thick!

Thanks.

1
2
3
4
C = !( (1 || 0 ) && 0 )
1. C = ! ( 1 || 0 )  //true OR false == because the 1's there it's true.

2. C = ! ( && 0 ) //true And false == there aren't two inputs so it's false? 

1. I don't know what you did to get to !(1 || 0) after the first step. The first thing you should do is evaluate (1 || 0), which is 1 (true) because true OR (anything) is true.

2. This step should read C = ! ( 1 && 0 ) because you put the 1 in place of the previous operation
i.e. (1 || 0)

//true And false == there aren't two inputs so it's false?

Maybe you're misinterpreting my comments? Each comment is describing the answer to the previous step. The comments are explaining why the statement looks like it does at the current step.

Then altogether there is 2 trues and 1 false, does this make the overall outcome true, which is why the answer is one?

The answer at each step only affects how the statement will look before the next operation. You work from inside to outside like you're putting together a Russian doll until you have a final answer (i.e. there are no operators left).
Last edited on
Ahhh. Now I understand. They're a bit similar to logic gates I did in college. But that's helped a lot. Can move on now.

Thank you! :D
Topic archived. No new replies allowed.