Jump to content
  • Advertisement


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


What is bit operators and how are they used?

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

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
Share on other sites
I dug around and found these old notes:

- 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

& 0101


- bitwise exclusive OR
- returns 1 when either bit but not both are 1

^ 0101

- 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

| 0101


- moves each bit in operand to the right the indicated number of places
- shifting right one bit same as dividing operand by 2


- 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


- reverses each bit
- complementing a number twice returns the orginal number

[edited by - lessbread on July 18, 2002 2:10:24 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!