# Thread: Boolean Operators?

1. ## Boolean Operators?

Hi,
I'm used to boolean operators and understand that they can be very useful, including in areas such as If...Then statements, etc. but I am thoroughly confused after reading the tutorial on the cprogramming site concerning If...Then statements which included some information on Boolean operators. I wrote a small program to try and test out what the author was saying and the results left me bewildered. Here is the code:
Code:
```#include <iostream.h>
int main()
{
cout<<(!1); // Not 1.
cout<<(!0); // Not 0.
cout<<(1 && 0);
cout<<(1 || 0);
return 0;
}```
The first two make perfect sense - if you have one and your looking for the negation its gonna be 0 and the second one is going to be one. But why does one and zerio (1 && 0) equal 0 and one or zero equal (1 || 0) one? I'm guessing perhaps it is because a number cannot be 1 and 0 but it can be 1 or 0 thus 1 and 0 must be false (0) and 1 or 0 can be true?
Respectfully,
David.

2. I'm guessing perhaps it is because a number cannot be 1 and 0 but it can be 1 or 0 thus 1 and 0 must be false (0) and 1 or 0 can be true?

First off, in C++, false=0 and true=1.

Then, it's just a matter of understanding your truth tables. For the compound statement (A && B) to be true, both A and B have to be true. So, if you have (1 && 0), since both terms aren't true, the compound statement will always be false.

For the compound statement (A || B) to be true only one term has to be true. So, in the statement (1 || 0), one term is true, so the compound statement will always be true.

For the first two statements:

!1 means !(true) which is false or zero, and !0 means !(false) which is true or one.

3. I suggest not getting all your knowledge from the tutorials on this board. Many, if not all, are very much outdated. If you are really interested get a book. Before you ask for book recommendations make a search on the board...there have been many threads about it.

4. Thanks for the advice and explanation of Boolean. I'll keep my eyes open for a good C++ book.
Respectfully,
David.

5. Strictly speaking, the statements false=0 and true=1 are false. Integers and booleans are of different types. In a boolean context though, 0 evaluates to false, and 1 (or any non-zero number) evaluates to true.

6. An AND gate is like a series circuit, if and only if both switches are closed does current flow, whereas the OR gate is a parallel circuit, if either switch is closed, current flows. With these two gates and the inverter (it's output is reverse of input) you can build NAND, NOR, XOR, and CNC gates. You can use simple combinations of these gates to add binary digits, too...

7. I have to ask, Sebastiani, what's a CNC gate?

8. The coincidence gate, it's an XOR gate with an inverted output. It's characteristic is that it outputs true if either both inputs are zero or both are one.

9. isn't it called an XNOR?

how would you write out an XOR using only AND,OR, and NOT gates?

http://educ.queensu.ca/~compsci/unit...c/summary.html <= an neat chart summarizing this stuff and showing symbols, etc.

10. That is the correct term, XNOR, but it is sometimes called the coincidence gate because it returns true if both inputs are the same.

XOR gate:

You can make an XOR gate by AND'ing the output of an OR gate with a NAND gate.

11. ^oh... interesting... I'm still probably going to try to derive the XOR thing on my own anyway because I'm a loser and I do that stuff (write linked lists, recursive functions, memorize pi, random logic, random trig, etc) in my free time...

12. You can piece together a gate using combinations of them, too.
A NAND gate can be made using an AND gate with an inverted output, or you can invert the inputs of an OR gate to get one. An XNOR gate is the same.

Popular pages Recent additions