Advertisement

What is bit operators and how are they used?

Started by July 18, 2002 12:55 AM
2 comments, last by Zeraan 22 years, 4 months ago
In GDNet Lounge, a guy said something about interviewing with a question on bit stuff. I don''t understand how this stuff works: | & << >> etc. If someone can either explain those operators clearly (I know that << and >> shifts the bits, but I don''t understand exactly how they work) or point me to a site with tutorial on bit manipulation, I''d apprecriate this. I think I can optimize some of my game''s parts with bit manipulating if I think this is what it is...
I dug around and found these old notes:

AND &- operates like a 2 bit truth table- if either bit is zero, yield bit is zero too- both bits must be one for the yield bit to be one	0011      & 0101	----	0001	-------------------------------------------------XOR ^- bitwise exclusive OR- returns 1 when either bit but not both are 1	0011      ^ 0101	----	0110- an XOR applied twice yields the original operand-------------------------------------------------OR |- two bits ORed yield 1 if either or both bits are 1 and 0 if both bits are 0- used to combine bits from different variables into a single variable	0011      | 0101	----	0111-------------------------------------------------RIGHT SHIFT >>- moves each bit in operand to the right the indicated number of places- shifting right one bit same as dividing operand by 2-------------------------------------------------BITWISE LEFT <<- always shifts in 0 bits from the right discarding left most bits- each bit shifted is equivalent to multiplying by 2- so shifting left 3 bits is like muliplying by 8-------------------------------------------------BITWISE COMPLEMENT ~ (unary)- reverses each bit- complementing a number twice returns the orginal number  


[edited by - lessbread on July 18, 2002 2:10:24 AM]
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Advertisement
Ah thanks. *copies it down*
Now I understand. Ah, the freedom...
There is a good article on bitwise operations in C here on GDnet.

Henrym
My Site

This topic is closed to new replies.

Advertisement