#### Archived

This topic is now archived and is closed to further replies.

# Bitwise OR and AND

## Recommended Posts

What´s the diffrence between bitwise OR (|) and AND (&&)?

##### Share on other sites
check your lovely c/c++ reference book...

because i''m a nice dude:

0&0 = 0
0&1 = 0
1&0 = 0
1&1 = 1

0|0 = 0
0|1 = 1
1|0 = 1
1|1 = 1

"take a look around" - limp bizkit

##### Share on other sites
Also, be careful with your |s, ||s, &s and &&s.

The ones with the double symbols (|| and &&) are logical operators as opposed to bitwise ones.

How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

##### Share on other sites
would you like coffee OR tea?
would you like coffee AND tea?
would you like coffee XOR tea?

simple, isn''t it?

##### Share on other sites
I don''t know, maybe it should be "do you have coffee and tea?"

How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

##### Share on other sites
For bitwise OR(|) the result is 1 if either of the two bits is 1.

For bitwise AND(&) the result is 1 if BOTH of the two bits is 1, and always 0 otherwise.

For bitwise XOR(^) called "exclusive or" the result is 1 if either of the two bits is 1, BUT NOT IF BOTH are 1 or BOTH are 0.

"aut viam inveniam aut faciam " - I will either find a way or make one.

MoonStar Projects

[edited by - Ronin Magus on December 27, 2002 11:12:21 AM]

##### Share on other sites
Just a note; in normal language, "or" is usually equivalent to logical eXclusive OR (XOR). The expression "and/or" is equivalent to logical OR.

So,
OR.: would you like coffee and/or tea?
AND: would you like coffee and tea?
XOR: would you like coffee or tea?

##### Share on other sites
CWizard, great sig I was thinking of doing something like that...

but now I can''t, because I would be copying you

"aut viam inveniam aut faciam" - I will either find a way or make one.

MoonStar Projects

##### Share on other sites
quote:
would you like coffee XOR tea?

how would one pronounce this? eks-or or zor?

##### Share on other sites
quote:
would you like coffee XOR tea?

how would one pronounce this? eks-or or zor?

##### Share on other sites
I usually say ix-or...

ToohrVyk
-------------
Extatica - a free 3d game engine
Available soon!

##### Share on other sites
I'm the opposite, I say "zor". And I couldn't tell you, because when my professors said do a xor operation, they just said "exclusive or."

"aut viam inveniam aut faciam " - I will either find a way or make one.

MoonStar Projects

[edited by - Ronin Magus on December 27, 2002 2:53:22 PM]

##### Share on other sites
ex-or. It is, after all, short for "exclusive". And exclusive doesn''t have a z in it.

Don''t listen to me. I''ve had too much coffee.

##### Share on other sites
neither does xylophone or xebra...

##### Share on other sites
Who knows what kind of accents people speak with

##### Share on other sites
quote:
Original post by krez
how would one pronounce this? eks-or or zor?

I said Zor once and my professor hit me
I think Eks-Or is more widely used.

##### Share on other sites
quote:
Original post by krez
neither does xylophone or xebra...

if you refer to the zebra (the black''n''white horse style animal) here, uhm, yes, it actually does.
xylophone is spoken gsilofon here :D(okay, ex-ilophone for you, i think)

"take a look around" - limp bizkit

Oh Man!

##### Share on other sites
Then how about Xerox?? as Zeroks?

##### Share on other sites
You guys are forgetting the shoot-em-up classic Xenon II...

How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

##### Share on other sites
And I? ex-a ex-a?

Just to avoid being deleted:

Given two binary numbers: 0100101010 (298)
1101011011 (859)

     binary      dec     0100101010 (298)AND  1101011011 (859)      ----------     0100001010 (266) ___________________________     0100101010 (298)OR   1101011011 (859)      ----------     1101111011 (891) ___________________________     0100101010 (298)XOR  1101011011 (859)      ----------     1001110001 (625)

##### Share on other sites
Further anti-delete protection:

Say, I noticed that the XOR operation was like an addition operation without the carry! Care to elaborate?

##### Share on other sites
It''s pronounced zor.

swift URL | browse my bookmarks [server may not always be on]

##### Share on other sites
And XOR can be used to switch variables without a temp!

ToohrVyk
-------------
Extatica - a free 3d game engine
Available soon!

##### Share on other sites
quote:
Original post by Zipster
Say, I noticed that the XOR operation was like an addition operation without the carry! Care to elaborate?

True, or rather that addition is xor with carry

Here's a diagram for a full-adder (if I get it right, that is ):
si = (ai XOR bi) XOR ci;ci+1 = ai * bi + (ai OR bi) * ci; ci o-----------------------+                           |             +-----+       |   +-----+ai o-----+-->|     |    +--|-->|     |         |   | XOR |>---+  |   | XOR |>-------------------o si      +--|-->|     |    |  +-->|     |      |  |   +-----+    |  |   +-----+      |  |              |  |      |  |   +-----+    |  |   +-----+          +-----+      |  +-->|     |    +--|-->|     |   +----->|     |      |      | AND |>-+    |   | AND |>--+      | OR  |>--o ci+1bi o--+----->|     |  |    +-->|     |      +-->|     |             +-----+  |        +-----+      |   +-----+                      |                     |                      +---------------------+

a = input bit 1
b = input bit 2
s = sum
c = carry

EDIT: Some formatting

[edited by - CWizard on December 28, 2002 5:54:46 AM]

[edited by - CWizard on December 28, 2002 5:58:11 AM]

• ### Forum Statistics

• Total Topics
628375
• Total Posts
2982310

• 10
• 9
• 14
• 24
• 11