Public Group

#### Archived

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

# What is bit operators and how are they used?

This topic is 5994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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...

##### Share on other sites
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]

##### Share on other sites
Ah thanks. *copies it down*
Now I understand. Ah, the freedom...

##### Share on other sites
There is a good article on bitwise operations in C here on GDnet.

Henrym
My Site

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013598
×