Ooops
December 03, 2021, 00:07:52

### Author Topic: bitflag : logic operators on integers  (Read 1147 times)

#### meems

• Sr. Member
•    • Posts: 310 ##### bitflag : logic operators on integers
« on: September 25, 2018, 16:49:11 »
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

• Full Member
•   • Posts: 225 ##### Re: bitflag : logic operators on integers
« Reply #1 on: September 25, 2018, 18:17:24 »
1 & 2 is 'bitwise and'
1 and 2 is 'logical and'

#### dawlane

• Full Member
•   • Posts: 209 ##### Re: bitflag : logic operators on integers
« Reply #2 on: September 25, 2018, 18:26:22 »
See the BlitzMax documentation Language Reference->Expresions
Example:
Code: [Select]
`Graphics 640,480Global bits:Int=0Const KLEFT:Int = 1Const KRIGHT:Int = 2Const KUP:Int = 4Const KDOWN:Int = 8Const KFIRE:Int = 16Global 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 FlipWend`
« Last Edit: September 25, 2018, 18:33:11 by dawlane »

#### meems

• Sr. Member
•    • Posts: 310 ##### Re: bitflag : logic operators on integers
« Reply #3 on: September 25, 2018, 19:44:30 »
thanks.
bah should have known. Tried && but didn't try &.