May 26, 2019, 03:19:13 AM

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

#### meems

• Sr. Member
•    • Posts: 310 ##### bitflag : logic operators on integers
« on: September 25, 2018, 04:49:11 PM »
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: 157 ##### Re: bitflag : logic operators on integers
« Reply #1 on: September 25, 2018, 06:17:24 PM »
1 & 2 is 'bitwise and'
1 and 2 is 'logical and'

#### dawlane

• Jr. Member
•  • Posts: 84 ##### Re: bitflag : logic operators on integers
« Reply #2 on: September 25, 2018, 06:26:22 PM »
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`

#### meems

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