Logic operators (super confused here)

I wrote my instructor a message, and this is what he sent back. I'm simply going to breakdown what he said, and hopefully, with some time, you guys can help me understand.

Logical AND, OR and NOT are more precise than when we use those terms in speaking. First, let's review the truth tables for each:

AND (&&)

0 && 0 = 0

0 && 1 = 0

1 && 0 = 0

1 && 1= 1

OR (||)

0 || 0 = 0

0 || 1 = 0

1 || 0 = 0

1 || 1= 1

NOT (!)

! 0 = 1

! 1 = 0

I don't understand these truth tables. Can someone explain?


If you take an AND and NOT it, you have a NAND: !(a&&b)

what is Nand saying? It's not boxes and chocolates? So, if boxes and chocolates come back as true, it's false and vice versa?

If you take an OR and NOT it, you have a NOR: !(a||b)

What is the Nor saying? It's neither beans or apples? So if beans or apples comes back as true, it's false?


All these things (AND, OR, NOT, NAND and OR) can be built in electronic parts and are known as 'gates'. Gates are the building blocks for the CPU in a computer.

How can AND, OR, NOT, NAND, and OR be built in electronic parts? Can someone give me a brief explanation.

Since these same logical operations are available to a programmer, a program can be written to simulate a computer.

Perhaps it's because I have issues with wording, but I didn't understand this sentence.

The NOT operator is most often used to test NOT equal (!=) or to test if a boolean is the opposite of what it claims. For example, if we have a boolean variable called isFast. NOT isFast (!isFast) would imply we are looking for when it's slow.

Why would we want this? I don't understand.

"Since !(temperature > 100) is equivalent to "is the temperature not greater than 100", wouldn't the answer to that question in all cases by "yes that's true". "

!(temperature > 100)

No. What you said next IS true.

Why isn't it true though? He didn't explain why.

"If the temperature is greater, it comes back as false.
If the temperature is not greater, it comes back as true. "

Wouldn't this be useful only if you want to trick someone? I'm not understanding."

Sometimes logic can get pretty tricky. So, we strive to keep it simple. Using NOT with less/greater than, may be confusing. Another way to express the same thing is

temperature <= 100

...which may be more clear?

That didn't make things clearer for me.

"If age is greater than 12 OR age is less than 62 then No matter what value is in age, one condition or the other must be true. That means the whole expression must always be true. This statement likely meant to use AND."

This is a case where English is not too precise.

12 < age || age < 62 yes, this would ALWAYS be true.

This part makes sense.

12 < age && age < 62 this describes what would usually be expressed like this: 12 < age < 62, or as the range of numbers between 12 and 62

The 12 < age < 62, or as the range of numbers between 12 and 62 confuses me. Why are we setting it up like 12 < age < 62?

I understand why it would make more sense to use and, however.

One more thing to consider; recall when you studied sets and number lines? You used the open and closed circle on the number line to indicate that a number was included or not:

< 100 - open circle, 100 is NOT included

<= 100 - closed circle, 100 IS included

I never used an open or closed circle, so I'm not sure what he's saying here.

I don't understand these truth tables. Can someone explain?


It's the rules of these operators.

AND (&&)

0 && 0 = 0

0 && 1 = 0

1 && 0 = 0

1 && 1= 1


AND operator takes two values, and gives a single value result. The input values (of which there are 2) can be 0, or 1.

0 && 0 = 0

If the two input value are 0, the output value is 0.


How can AND, OR, NOT, NAND, and OR be built in electronic parts?

I don't understand your question. Are you asking how electronic things work? That's a huge question.

You know what, forget everything you said above. Start again. With one question only. What is the very first thing you don't understand? The very first, simplest thing that you don't understand.
Truth tables. : )
Do you understand how to look up information from a table? Like this, for example:

             City      Age

Joe        London      34
Bill       Moscow      21



What is Bill's city?
Last edited on
Moscow. I believe so?
How about this table?

       Input A -> 0      1
Input B
      0           0      0
      1           0      1


If input A is 0, and input B is 0, what's the answer? Look at the table. See the column for Input A as 0, see the row for input B as 0, what value does the table tell you?
Last edited on
That definitely confused me.
Hold your finger to the top line. The top line shows all the possible values of "Input A", going along the top. You can see that there are two possible values for Input A. Can you tell me what the two possible values for Input A are?

Hold your finger to the left column. The left column shows all the possible values of "Input B". You can see that there are two possible values for Input B. Can you tell me what the two possible values for Input B are?
For Input A I believe the values are 0 and 1

Input B
0 0 0
1 0 1

This part is confusing me the most. I can't tell you what the values for B are.
What if i take out everything that isn't directly concerned with showing you all possible values of B:

Input B
    0          
    1


Now, what are the possible values of Input B?

There is no trick to this. The complete table is a way of showing you what the output is for any combination of the two inputs.

In the previous table, the possible values of Input A were: City, Age
In the previous table, the possible values of Input B were: Joe, Bill

Last edited on
0 and 1

But how do you explain the rest of the 0's and 1's in the original table?
closed account (37oyvCM9)
true and false
closed account (37oyvCM9)
&& means a and b must both evaluate to true for the statement to be true.
|| means a or b can be true for the statement to evaluate to true.

am I right here lol...prob not im a newb to
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
  std::cout << "OR - only one proposition needs to be true or otherwise false" << std::endl;
  std::cout << (int )(true || true) << std::endl;
  std::cout << (int )(true || false) << std::endl;
  std::cout << (int )(false || true) << std::endl;
  std::cout << (int )(false || false) << std::endl << std::endl;
  
  std::cout << "AND - both propositions must be true or otherwise false" << std::endl;
  std::cout << (int )(true && true) << std::endl;
  std::cout << (int )(true && false) << std::endl;
  std::cout << (int )(false && true) << std::endl;
  std::cout << (int )(false && false) << std::endl;
}


OR - only one proposition needs to be true or otherwise false
1
1
1
0

AND - both propositions must be true or otherwise false
1
0
0
0


Note: true evaluates to integer 1, false to integer 0
Last edited on
Topic archived. No new replies allowed.