Difference between Bitwise External/Internal Inclusive OR?
Moderator: Coders of Rage
Difference between Bitwise External/Internal Inclusive OR?
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?
- Ginto8
- 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?
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.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?
examples:
Click here to see the hidden message (It might contain spoilers)
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.
- dandymcgee
- 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?
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!
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Difference between Bitwise External/Internal Inclusive OR?
There's quite a few, here: http://aggregate.org/MAGIC/dandymcgee wrote:Has anyone discovered any neat little tricks using bit manipulation?
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.
- teamtwentythree
- 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?
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)