Jump to content
  • Advertisement

Archived

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

Teric

Bitwise operation question

This topic is 5865 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 trying to figure out the bitwise reverse of a UINT. For example, if I have the number 23, the binary code is 0010111. The bitwise reverse of 23 would be 1101000, or 208. Is there an operator or function that will do this for me? Or do I have do code the thing bit by bit? Thanks in advance!
I am always open to feedback, positive or negative...

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Alternatively you can XOR your number against the max value for your bitfield. Assuming a 32 bit bit-field:

inverseBitField = bitField ^ 0xFFFFFFFF;

The nice part about doing it this way is that you can flip a portion of your bit-field without affecting the rest of it, like this:

inverseBitField = bitField ^ 0xF0;

Which would ONLY flip the 5th through 8th least signifcant bits.

If you just want to flip the whole number though, using a Logical-NOT is probably the way to go (the ~ operator mentioned in the previous post).

Hope that helps,

-FlowerChild

Share this post


Link to post
Share on other sites
That''s great! Thanks for the help.


I am always open to feedback, positive or negative...

Share this post


Link to post
Share on other sites
quote:
Original post by Teric
I''m trying to figure out the bitwise reverse of a UINT.

For example, if I have the number 23, the binary code is 0010111. The bitwise reverse of 23 would be 1101000, or 208.


That would be the bitwise inverse .
1110100 (116) would be the bitwise reverse.

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!