Opposite of '|'?

BlitzMax Forums/BlitzMax Programming/Opposite of '|'?

JoshK(Posted 2009) [#1]
1|2 is 3.
3|2 is 3.
3?1 is 2.
2?1 is 2.

What is "?"


_Skully(Posted 2009) [#2]
with the | (or operator) you are combining bits...
with the & (and operator) you are filtering them

3&2 is 2

2*1 is 2


JoshK(Posted 2009) [#3]
I want to subtract a value from another value if it exists in the value:

if (a & b) b=b-a


_Skully(Posted 2009) [#4]
I use this when using bitwise parameters

for example, in TileMax I pass an integer flag for drawing the layers

Flag:int=Layer1 shl 1+Layer2 shl 2+layer3 shl 3+layer4 shl 4

then to determine if they are set I go

DrawLayer1: if flag & %00000001
DrawLayer2: if flag & %00000010
DrawLayer2: if flag & %00000100
DrawLayer2: if flag & %00001000


Tommo(Posted 2009) [#5]
AND its mask.
A & (~B)


_Skully(Posted 2009) [#6]
You have to be working Bitwise for that to work... you just use your powers of 2

so...yes

if (a & b) B:-a


N(Posted 2009) [#7]
Strict

Local a:Int = $FFFFFF
Local b:Int = $00FF00

If a & b Then
	Print Hex(a)+" contains bits "+Hex(b)
	a = a&~b
Else
	Print Hex(a)+" does not contain bits "+Hex(b)
EndIf

If a & b Then
	Print Hex(a)+" contains bits "+Hex(b)
	a = a&~b
Else
	Print Hex(a)+" does not contain bits "+Hex(b)
EndIf


Something like that? If you want to remove bits that are set after you know they're set, ~ (binary not) the flag and then filter them out from the initial value.

Also, a&b is not the same as b&a (I think? Now I'm not so sure anymore), so in your example you're.. well, I'm not sure what your example is doing, but hopefully I understood what you were intending to do.


JoshK(Posted 2009) [#8]
That does it:
Const FLAG1 = 1
Const FLAG2 = 2
Const FLAG3 = 4

Local flags=1|2|4

Print (FLAG3 & flags)

flags=flags &~ FLAG3

Print (FLAG3 & flags)



Chroma(Posted 2009) [#9]
Josh, do me a favor and ask if anyone knows how to start an external app with arguments. You seem to get 10x the responses as me...


_Skully(Posted 2009) [#10]
I would have answered if I had the answer ;)

Besides, what are YOU talking about? I cant even get someone to quickly test Tilemax ;) lol


JoshK(Posted 2009) [#11]
That's easy, you just use CreateProcess() and pass the command line arguments in either a second parameter, or after the executable name. I forget which.