Skip to main content
GameDev.net gamedev.net
🔒 Locked

Flip bits

Started by silverphyre673 Oct 24, 2005 at 11:57 PM 2 replies 300+ views
Original Post
silverphyre673
silverphyre673
I have a char variable (1 byte) equal to zero. I know I remember someone posting something about this, but I need to flip each bit in the byte to equal 1, so the byte is equal to the maximum value of a char. Anyone know how to do this? Thanks.
my siteGenius is 1% inspiration and 99% perspiration
silverphyre673
silverphyre673
Excellent. Forgot about the ~! Thanks.
my siteGenius is 1% inspiration and 99% perspiration
eq
eq
If you wan't to flip individual bits use xor:

unsigned char c = 0x10;
c ^= 0x0f; // Inverts the lower 4 bits
printf("0x%02x", c);

Will display: 0x1f;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.