Bitwise operations??

BlitzMax Forums/BlitzMax Beginners Area/Bitwise 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.

Hello,

I'm trying to fingure out how to do bitwise operations in Max. All I want to do is be able to set or clear bits based on a bitmask.. For example, in other languages, & and || always did this fine. For some reason it isn't porting over to max well for me. Here is a simple test i whipped up. I have a value of 3 being held in a variable called flag (bits 1 and 2 set). I am trying to use & and | to toggle bit 1 on/off... Which should result in the flag variable toggling between 2 and 3.. DOesn't seem to be working...
I understand I can use XOR for this, but i don't simply want to toggle the bits, I want to set them if not set, and/or clear them if not cleared.. Here is my sample code. Am I doing something wrong, or is this Max related??

Graphics 640,480

Global Flag:Byte = 3
Global bitmask:Byte = 1

While Not KeyDown(KEY_ESCAPE)
	Cls
	DrawText("BITWISE OPERATOR TEST",10,10)
	DrawText("Use 7 to do an & operation (bitmask of "+bitmask+")",10,30)
	DrawText("Use \ to do an | operation (bitmask of "+bitmask+")",10,50)
	DrawText("Flag Value: " + flag,10,70)
	
	If KeyHit(KEY_7) '& operation
		flag = (flag & bitmask)
	EndIf
	
	If KeyHit (KEY_BACKSLASH) '| operator
		flag = (flag | bitmask)
	EndIf
	
	FlushMem
	Flip
Wend
End