Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / [SOLVED] Setting and clearing bits

Author
Message
Jambo B
14
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 11th Oct 2020 11:16
Hello

Am I right here -

I can set a bit like this:
Flags as integer
Flags = Flags || 8

I can read a bit like this:
if Flags && 8 then...

HOW do I clear a bit without knowing first whether it's 0 or 1?

Thanks for any help.

The author of this post has marked a post as an answer.

Go to answer

MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 11th Oct 2020 11:20
Hi,

with EXCLUSIVE OR (short XOR)

In your example.
Flags = Flags ~~ 8

Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Jambo B
14
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 11th Oct 2020 11:26
Thanks Madbit. The flags still seem to be affected though, if bit 8 wasn't set in the first place.

Flags = 2
Flags = Flags ~~ 8
Now - Flags = 10

I'd like Flags to still = 2 at the end, because bit 8 wasn't set at the beginning, if you see what I mean.
Jambo B
14
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 11th Oct 2020 11:59 Edited at: 11th Oct 2020 12:00
Think I've figured out a workaround, but it's a bit clunky:



I wonder if there's a more elegant way to do it.
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 11th Oct 2020 13:48
This post has been marked by the post author as the answer.
Yeah, you're right. XOR toggles the bit. Then try a combination of XOR and AND.

something like this.

Flags = Flags && (Flags ~~ 8)
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Login to post a reply

Server time is: 2024-03-29 09:02:47
Your offset time is: 2024-03-29 09:02:47