#### Archived

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

# Bitwise operation question

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

## 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 on other sites
bitwiseNotOfValue = ~value;

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

##### Share on other sites
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 on other sites
That''s great! Thanks for the help.

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

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

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 12
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633315
• Total Posts
3011328
• ### Who's Online (See full list)

There are no registered users currently online

×