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

Flipping bits

Started by Floru Nov 22, 2001 at 8:26 AM 1 replies 450+ views
Original Post
Floru
Floru
Hi. How can I simply change all bit values to opposite from a number. So that all 0''s would be 1''s and opposite. I tried using not (!) but it didn''t work because it only gives you 0 or something else (only for boolean things). Floru
henryx
henryx
Use the complementary operator ~

e.g.

x = ~x;

henry
HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK
Spinal Confusion
Spinal Confusion
quote:
Original post by Floru

Hi.

How can I simply change all bit values to opposite from a number. So that all 0''s would be 1''s and opposite. I tried using not (!) but it didn''t work because it only gives you 0 or something else (only for boolean things).

Floru


Use ~ in front of the variable.

-Steven

Topic Locked

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

Sign in to reply to this topic.