Difference between Bitwise External/Internal Inclusive OR?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Difference between Bitwise External/Internal Inclusive OR?

Post by XianForce »

I've seen these two operators in code here and there... but I've never been able to find their differences/specialties, nor did a google search help much. So does anyone have something to enlighten me on these two operators?
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Difference between Bitwise External/Internal Inclusive OR?

Post by Ginto8 »

XianForce wrote:I've seen these two operators in code here and there... but I've never been able to find their differences/specialties, nor did a google search help much. So does anyone have something to enlighten me on these two operators?
please rephrase and show us the symbols used for them =P I don't remember all the programming jargon. If by external inclusive or you mean the ~ symbol, it does a boolean NOT on each of the individual bits of the expression. | does a boolean OR between the bits of 2 expressions. & is like |, just AND instead of OR. ^ is XOR.
examples:
Click here to see the hidden message (It might contain spoilers)

Code: Select all

NOT:
var | returned
0    | 1
1    | 0

OR:
var1 | var2 | returned
0    | 1    | 1
0    | 0    | 0
1    | 0    | 1
1    | 1    | 1

AND:
var1 | var2 | returned
0    | 1    | 0
0    | 0    | 0
1    | 0    | 0
1    | 1    | 1

XOR:
var1 | var2 | returned
0    | 1    | 1
0    | 0    | 0
1    | 0    | 1
1    | 1    | 0

And I've just explained pretty much all of C/++'s bitwise operators.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Difference between Bitwise External/Internal Inclusive OR?

Post by dandymcgee »

This seems like a good topic to ask what bitwise operators are most commonly (or not so commonly) used for. Has anyone discovered any neat little tricks using bit manipulation?
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Difference between Bitwise External/Internal Inclusive OR?

Post by MarauderIIC »

dandymcgee wrote:Has anyone discovered any neat little tricks using bit manipulation?
There's quite a few, here: http://aggregate.org/MAGIC/
Some of which are:
Is Power of 2

A non-negative binary integer value x is a power of 2 iff (x&(x-1)) is 0 using 2's complement arithmetic.
Integer Constant Multiply

Given an integer value x and an integer or floating point value y, the value of x*y can be computed efficiently using a sequence derived from the binary value of x. For example, if x is 5 (4 + 1):

y2 = y + y;
y4 = y2 + y2;
result = y + y4;

In the special case that y is an integer, this can be done with shifts:

y4 = (y << 2);
result = y + y4;
Integer Power

Given an integer value x and an integer or floating point value y, the value of y to the x power can be computed efficiently using a sequence derived from the binary value of x. For example, if x is 5 (4 + 1):

y2 = y * y;
y4 = y2 * y2;
result = y * y4;
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
teamtwentythree
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 72
Joined: Wed Apr 16, 2008 12:19 am
Location: Seattle, WA

Re: Difference between Bitwise External/Internal Inclusive OR?

Post by teamtwentythree »

A fairly obvious use. I use bitwise operators to store/retrieve booleans from bytes when sending data over the "tubes". I also use bit shifting in case I'm mixing data in one byte (Like a 4-bit int + 4 1-bit bools)
Post Reply