# Newbie question !( 1 || 0 ) - ?

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 03-30-2005
anbdesigns
Newbie question !( 1 || 0 ) - ?
I was going through Lesson 2 in the tutorials. At the end, it has some statements ~
Code:

```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)```
What does the ! do here?
How does 1 && 0 evaluate to 0? (previous paragraph in tutorial)

Thanks :D
• 03-30-2005
mrafcho001
! means not

for example:
Code:

``` a = 1; if( a != 3 ) {   cout << "blah Blah" << endl; } //OUTPUT: blah blah //because a  is not 3..```
• 03-30-2005
SirCrono6
> How does 1 && 0 evaluate to 0?
How can something be true and false?

- SirCrono6
• 03-30-2005
anbdesigns
Quote:

Originally Posted by SirCrono6
> How does 1 && 0 evaluate to 0?
How can something be true and false?

- SirCrono6

Maybe I'm reading into it too much..

All I get from !(1 && 0) is "Not(True AND False)" I don't see how an answer can come from that :D

I understand If statments quite well :)
• 03-30-2005
7stud
Hi,

AND requires both terms to be true for the result to be true, where OR only requires one term to be true for the result to be true. So, starting with the parentheses:

(True AND False)

you get:

(false)

because both terms aren't true. Then, NOT reverses the result, so

!(false)

gives you true.

!(true OR false)

since OR only requires one term to be true for the result to be true, you would get:

!(true)

which is false.
• 03-30-2005
Zach L.
Don't read too much into the names given to the logical operators ('and', 'or' ... especially 'or'). The meanings of these words in English does not completely correspond to their logical meanings, just take them as definitions.

p && q is true if and only if p is true and q is true
p || q is false if and only if p is false and q is false
!p is true if and only if p is false

Cheers
• 03-30-2005
anbdesigns
Ok, that makes sense now.. Thanks for clarifying :)
• 03-30-2005
misplaced
i'm sure you probably know, but i haven't seen anyone point this out, so i will. anything that evaluates to zero evaluates to false;
anything that evaluates to anything that's NOT zero, evaluates to true.

if you REALLY want to learn about logic operators, i suggest reading some ASM tutorials concerning bitwise operations.

just a little example of logic operators in it's binary form
Code:

```1010 1000 && ---------- 1000  = true (not zero)  //  !1000 = false 1010 0100 || --------- 1110  = true (not zero)  //  !1110 = false; 0101 0101 XOR //i forget the XOR operator in c/c++ (^ maybe?) ------------ 0000  = false (zero)    //  !0000 = true; for you specific question - 0001 0000 || ------------ 0001 true  // !0001 = 0000 = false```
• 04-02-2005
macman
I dont think there is a XOR operator availible in c++..some people say its a flaw..hu knows..a quick and easy work around is:

bool p, q;

(p || q) && !(p && q)

producing an xclusive OR..

cheers

Alex
• 04-02-2005
Salem
> I dont think there is a XOR operator availible in c++
Of course there is, and it's ^
• 04-02-2005
macman
is that quite a recent addition to c++?

becuase the book im reading says there isnt one..

man..i feel dumb!

cheers
Alex
• 04-02-2005
Salem
> is that quite a recent addition to c++?
No, it's there from original C, which means it's been there forever basically.
• 04-02-2005
Thantos
Of course what Salem is failing to state is that it's bitwise XOR :)
• 04-02-2005
macman
bitwise?

cheers
Alex
• 04-02-2005
Lithorien
Quote:

Originally Posted by macman
bitwise?

cheers
Alex

Bitwise:

00010001 XOR 00100001

00010001
00100001
-------------
00110000

Bitwise means that the XOR operator takes a look at the individual bits. XOR, in this case 'Exclusive OR', means that only one can be true to evaluate to true.

Does that help?
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last