bitflag : logic operators on integers

Started by meems, September 25, 2018, 16:49:11

Previous topic - Next topic

meems

in blitzplus
1 and 2 = 0

in blitzmax
1 and 2 = 1

Does blitzmax have the blitzplus functionality of logic operators on integers in some other operator \ function? Or do I have to write my own bitflagbank compare function?

GW

1 & 2 is 'bitwise and'
1 and 2 is 'logical and'

dawlane

#2
See the BlitzMax documentation Language Reference->Expresions
Example:
Graphics 640,480

Global bits:Int=0

Const KLEFT:Int = 1
Const KRIGHT:Int = 2
Const KUP:Int = 4
Const KDOWN:Int = 8
Const KFIRE:Int = 16

Global out:String = ""

While Not KeyDown(KEY_ESCAPE)
bits = 0
out = ""
Cls
If KeyDown(KEY_LEFT) Then bits = bits | KLEFT
If KeyDown(KEY_RIGHT) Then bits = bits | KRIGHT
If KeyDown(KEY_UP) Then bits = bits | KUP
If KeyDown(KEY_DOWN) Then bits = bits | KDOWN
If KeyDown(KEY_LCONTROL) Then bits = bits | KFIRE

If (bits & KLEFT) Then out = out + " LEFT "
If (bits & KRIGHT) Then out = out + " RIGHT "
If (bits & KUP) Then out = out + " UP "
If (bits & KDOWN) Then out = out + " DOWN "
If (bits & KFIRE) Then out = out + " FIRE "

DrawText " result: " + out, 100, 100
Flip
Wend

meems

thanks.
bah should have known. Tried && but didn't try &.