# How to store multiple boolean values in a binary string?

## Recommended Posts

I need a binary variable to contain multiple Boolean values, I am not sure if it has to do the Bit function as I don't know much about them. I searched the forums to no avail, any help is very much appreciated as always, thank you.

##### Share on other sites

Define a power of 2 list of flags, for example:

Dim \$fVisible = 1

Dim \$fShiny = 2

Dim \$fTiny = 4

.

.

.

Dim \$fDUmmy = 0x40

And check it's bit to react upon to:

Or, am I completely far beyond understanding?

##### Share on other sites

Sorry my description was vague, we are on the right path I believe though. =) How would I go about checking if just one specific value is true? Also how do I generate the \$fDUmmy in your question? Sorry I am quite noob with these.

Edited by foster74

##### Share on other sites

binary as in 1 0 1 0 0 1 1 0 1 1

##### Share on other sites

You can have N flag for N bits variable, so 32 bit int for example contain 32 possible flags instead of declaring 32 boolean variables or 32 int in this matter.

I'll try to describe it better as I can:

```; These are the properties you may want to determine if are set '1' or aren't '0':
Enum Step *2 \$fVisible, \$fShiny, \$fTiny, \$fDummy, \$fLucky, \$fStrike

; A variable that holds a few properties:
Dim \$fVar = BitOR(\$fVisible, \$fTiny, \$fLucky, \$fStrike)

; Checking each property, if a property set BitAND result in a value greater then 0, else, 0.
; Same as If BitAND(\$Var, \$fProperty) > 0 Then ...:
If BitAND(\$fVar, \$fVisible) Then ConsoleWrite('Visible is set' & @LF)
If BitAND(\$fVar, \$fShiny) Then ConsoleWrite('Shiny is set' & @LF)
If BitAND(\$fVar, \$fTiny) Then ConsoleWrite('Tiny is set' & @LF)
If BitAND(\$fVar, \$fDummy) Then ConsoleWrite('Dummy is set' & @LF)
If BitAND(\$fVar, \$fLucky) Then ConsoleWrite('Lucky is set' & @LF)
If BitAND(\$fVar, \$fStrike) Then ConsoleWrite('Strike is set' & @LF)```

##### Share on other sites

binary as in 1 0 1 0 0 1 1 0 1 1

Whatever works best, not sure, but had that in mind... But I'd prefer to use a single line of code to figure out if a certain value is 1 or 0 if possible. Like lets say;

Value1 = true

Value2 = false

Value3 = true

I'd like to keep these in a single string and use one line to check and/or modify the data. Such as:

If Value1 = true Then value1 = false.

I hope I'm not confusing anyone. =)

##### Share on other sites

Perfect example Authenticity, exactly what I was looking for, this will help me with storing and parsing data a ton! Thanks a million! =)

Edit: Oh a quick follow up question. What's the correct way to deselect a value?

`If BitAND(\$fVar, \$fTiny) Then \$fVar -= \$fTiny`

Is what I am thinking, is there a better way?

Edited by foster74

## Create an account

Register a new account

×

• Wiki

• Back

• Git