View Single Post
Old 07-07-2005, 05:48 PM   #2 (permalink)
bla!!
 
Monster Techie

Join Date: May 2004

Location: /usr/root/mn/us

Posts: 1,121

bla!! is on a distinguished road

Default

Ok this might take a bit.

But lets go operator by operator.

Not
The only unary operatory (only works on one bit string) is the ~.

This operator does just what you described, it switches all 0's to 1's and all 1's to 0's.

For example
Code:
Starting Number: 11011001

~11011001 = 00100110
And

And (&) works on two bit patterns. It analyzes each corresponding bit position within each pattern. If both bits are the same (both are 1's or both are 0's), it results in a 1 in the final bit pattern, if they are different, it results in a 0.

For example
Code:
 
x     = 10010101
y     = 01011011
x & y = 00110001
Exclusive Or

Exclusive Or (^), sometimes referred to a XOR, also works on two bit patterns. It is the exact opposite of the and operator. If both bits are the same (both are 1's or both are 0's), it results in a 0 in the final bit pattern, if they are different, it results in a 0.

For example
Code:
These are the same numbers from the AND example.

x     = 10010101
y     = 01011011
x ^ y = 11001110

Notice how X^Y is the exact opposite of X&Y.
Or

The last bitwise operator is OR. This works very similar to the Exclusive Or. If both bits in the initial bit patterns are 1's, it results in a 0, for all other conditions it results in a 1.

For example
Code:
x     = 10010101
y     = 01011011
x | y = 11101110

I'll post back with some interesting uses of these later tonight. Right now it's time to get outta work!
__________________
<br>
Its a frigging Laptop, not a Labtop!!!!
bla!! is offline