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

Offline meems

  • Sr. Member
  • ****
  • Posts: 281
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?

Offline GW

  • Full Member
  • ***
  • Posts: 151
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'

Offline dawlane

  • Jr. Member
  • **
  • Posts: 82
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,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

Offline meems

  • Sr. Member
  • ****
  • Posts: 281
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 &.