Hi, I'm trying to go through the C++ tutorials, but I keep getting stumped when i hit the Boolean stuff. Could somebody please explain it in an easier way? Thanks

Printable View

- 09-11-2005Trogdor27Boolean operators
Hi, I'm trying to go through the C++ tutorials, but I keep getting stumped when i hit the Boolean stuff. Could somebody please explain it in an easier way? Thanks

- 09-11-2005Tonto
If you narrow down your question, I'm sure your problems will be addressed more promptly and you will understand much better than if some kind person came along and wrote up a big page about boolean logic. Perhaps, you could also use the resources the internet provides to help you narrow down your question:

http://computer.howstuffworks.com/boolean.htm

http://www.intap.net/~drw/cpp/cpp03_04.htm

http://www.cprogramming.com/tutorial/lesson2.html

etc. etc. etc. google. google. - 09-11-2005Trogdor27
Ok, I'm working on the tutorial 2, and I sort of understand the NOT operator, but the AND and OR are just beyond me. It gives this example:

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)

For A, i think this means NOT 1. 0 is not 1 so this would be true but the answer is 0 meaning false.

For starters, what am I not understanding in A? - 09-11-2005-JM
Holy deja vu, Batman! This was covered just a few posts ago:

http://cboard.cprogramming.com/cplusplus-programming/69525-so-confused-learning-something.html

I guess you have !(been reading the posts);

-JM - 09-11-2005Trogdor27
ok, i read that and it helps, but one question still:

How does ( 1 || 0 ) equal to 1?

It means 1 or 0. Does the OR operator only look for either of the values to be one and then it is true? Can the Or operator ever be looking for a zero? How about a seven?

Edit: I think I understand now. I had been thinking of 0 and 1 as numbers in the questions. Instead I should be thinking of them as true and false. This makes a lot more sense and gets me the correct answers for the examples. Now I can finally get on to tutorial 3 and continue my path to world domination. - 09-11-2005DaeQuote:

Originally Posted by**Trogdor27**

- 09-11-2005Trogdor27
Excellent, thank you for clarifying. Its all coming together now.

- 09-11-2005Rashakil Fol
You might be thinking of these as logical statements. Also think of the logical operators as mathematical functions. The ! operator is simply defined by f(x) = 0 if x != 0, 1 if x = 0.

The || operator is simply defined by f(x,y) = 0 if (x,y) = (0,0), 1 otherwise.

The && operator is simply defined by f(x,y) = 0 if x = 0, 0 if y = 0, 1 otherwise.

(Assume that true and false are stand-ins for 1 and 0.)

The || and && operators will stop after evaluating their left hand side if they can already deduce the answer, so sometimes, the right side does not get evaluated. It's good to know this. - 09-11-2005Queatrix
Trogdor27, I noticed you use your text gun as a sig, and yet it's not. If you made it a sig you wouldn't have to add it to each post.

- 09-11-2005DaeQuote:

Originally Posted by**Cool-August**

Quoting him doesnt seem to catch his gun sig.. doesnt seem like hes adding it manually. (nor is it included in the quotes below this text box) - 09-12-2005Trogdor27
its a sig