Ooops
December 03, 2021, 00:07:52

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

Offline 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?

Offline 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'

Offline 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,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
« Last Edit: September 25, 2018, 18:33:11 by dawlane »

Offline 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 &.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal