Jump to content
  • Advertisement


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


Getting bits out of an int...

This topic is 6932 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

I''m writing the net code for my game and am planning on optimising the data sent. Some of the data I''m sending will be unsigned numbers up to 128. How do I copy the lower say 7 bits so I can structure them in to a bit stream? What is the best way to address my bitstream, do I have to use some kind of data structure that uses bytes or is there something that I can used to organise my bits like an array? If I have to use bytes and my structure of data makes it so a number I want to store spans two bytes will I chop up the bits in the same manner as the copying method in Question 1? Many Thanks Chris...

Share this post

Link to post
Share on other sites
Use & man. The & is the bitwise-AND statement. Its basically used to test bits, So im not sure if it sets them too. Like this:

int var = 123;

To see if bit 2 is set, do:

if(var & 10b)

You can use hex instead of binary. I dont know if this helped any.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!