Find if flag is in number?

Miscellaneous Forums/General Discussion/Find if flag is in number?

As you can see, I have no idea what the words for this topic is, so even though it is completely possible to seek out the answer on a search engine, I would not be able to.


How can I do something like B3d's CreateTexture function, where I have a variable to which I add numbers like 1,2,4,8,16,32 and then later check which ones are there?

Well, a simple way that will work is to store them as strings: textureflags1="1*2*4*8*16*32" - baring in mind you won't be storing all of them so the asterisk is just a separator.

Well, a simple way that will work is to store them as strings: textureflags1="1*2*4*8*16*32" - baring in mind you won't be storing all of them so the asterisk is just a separator.
Er.... no...

X = 1+2+16+32
If X And 32
  ;do stuff for flag 32
EndIf
If X And 16
  ;do stuff for flag 16
EndIf


Thanks!

Wow, that's easy :)

Oh, but can't he process the string and add them at the point he needs to do the look-up to get the result?

Oh, but can't he process the string and add them at the point he needs to do the look-up to get the result?
What's the point? Processing a string will take hundreds of times longer, and to be blunt, is an utterly senseless way of doing this.

Oh.

Although, he never mentioned how often he was going to use it.

Still, I like your idea. Not bad at all.

Nearly as good as mine :)

puki that would only complicate things.

If A AND 32
endif

may work but I'd rather use the bulletproof version that is:

If (A And 32) = 32
endif

Cause (A And 32) will mask everything but the 6th bit. So if it's set, the result will be 32, otherwise zero.

We know there have been some issues with the parsing of mixed boolean condions in Blitz, If A And 32 may work, If A and 32 or 1 will fail, for example.

As well as:

flags= 1 or 2 or 4 or 8 or 16 ...
instead of
flags= 1 + 2 + 4 + 8...
Tho, the result is the same. Using AND and OR would be more kind of like the standard way to set or test bits.

a further reason is when you say
flags=flags + 4
twice,then you have set the flag 8 and unset the flag 4. Using OR twice will set the flag 4 nomatterwhat.

I might patent my way.

too late! But thanks for the contribution!