Please assist with bit operations.

BlitzMax Forums/BlitzMax Beginners Area/Please assist with bit operations.

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here's an example I knocked up from a previous module I wrote (unsure where I figured out how to do this).
EDIT: BAM! use the ~ operation to remove flags.
SuperStrict

'unsure if adding last value to new value is necessary
'though using 1-5 (in this example) outputs "Flags contains sq_EAST" 
'so theres something to this standard
'you can use bytes or ints for flag values
Const sq_NORTH:Int = 1, sq_SOUTH:Int = 2
Const sq_EAST:Int = 4, sq_WEST:Byte = 8
Const sq_VISITED:Byte = 16

'check if values exist in Flags
Local Flags:Byte = sq_NORTH | sq_WEST | sq_VISITED
testflags(Flags)
Print

Flags = flags ~ sq_NORTH
testflags(Flags)

Function testflags(Flags:Byte)
	If (sq_NORTH & Flags)
		Print "Flags contains sq_NORTH"
	Else
		Print "Flags does not contain sq_NORTH"
	EndIf
		
	If (sq_SOUTH & Flags)
		Print "Flags contains sq_SOUTH"
	Else
		Print "Flags does not contain sq_SOUTH"
	EndIf
	
	If (sq_EAST & Flags)
		Print "Flags contains sq_EAST"
	Else
		Print "Flags does not contain sq_EAST"
	EndIf
	
	If (sq_WEST & Flags)
		Print "Flags contains sq_WEST"
	Else
		Print "Flags does not contain sq_WEST"
	EndIf
	
	If (sq_VISITED & Flags)
		Print "Flags contains sq_VISITED"
	Else
		Print "Flags does not contain sq_VISITED"
	EndIf
End Function


EDIT: Ah weird, I did this using an integer, I'll play with a byte and post it soon.