Find if flag is in number?

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

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

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.