Jump to content
  • Advertisement


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

Arek the Absolute

Turning off a bit

This topic is 5830 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 feel stupid that I can''t seem to figure this out, but how do I turn off just one bit in a larger number? For example: If I have the number 00110001 (49) and I want to set bit 2 to 1, I know I can just use the inclusive or (|) with 00000100 (4) and it ends up 00110101 (53), which is what I want. What if I want to do it the other way around though? What if I wanted to, say, turn the first bit off instead? How would I turn 00110001 (49) to 00110000 (48)? I''ve tried using ^, but that has the nasty habit of switching the bit from on to off AND from off to on. Is there any way I can turn it OFF only, and leave it alone if it''s already on? It''s easy the other way around, and it annoys me that I can''t find a way here. I could just do if ((number&(1<

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!