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.

I think you do something wrong

flag & bitmask -> bitmask

and after that flag | bitmask -> bitmask as flag is already bitmask.

I think this is what you wanted:

Graphics 640,480,0

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_space) '| operator
		flag = (flag | bitmask)
	EndIf
	
	FlushMem
	Flip
Wend
End