What does ~ do in Blitz Max?

BlitzMax Forums/BlitzMax Beginners Area/What does ~ do in Blitz Max?

Rico(Posted 2008) [#1]
I assume its some kind of logical operator but I'm not sure which one. Also what other operators are there apart from this one?

Thank you!


tonyg(Posted 2008) [#2]
Check in your IDE : Help / Language / Expressions.
~ is Bitwise complement
Double meaning of ~


GfK(Posted 2008) [#3]
Check in your IDE : Help / Language / Expressions.
~ is Bitwise complement

Also used for escape codes, i.e:
Print "~qHello~q"
"Hello"


More in Language Reference>>Literals.


Rico(Posted 2008) [#4]
oh - ok thanks. It says its XOR. Ha ha I had a very geeky friend who used to say 'Do you want to go for lunch exclusive-or the pub?'

Yes I know it was sad, but he reckoned it stopped you choosing both.


TaskMaster(Posted 2008) [#5]
To keep you from going to the pub for lunch? He only wants to drink if you go the the pub?


markcw(Posted 2008) [#6]
I do Not know what Xor does.


ziggy(Posted 2008) [#7]
@markcw:
or:
0 or 0 = 0
0 or 1 = 1
1 or 0 = 1
1 or 1 = 1

and:
0 and 0 = 0
0 and 1 = 0
1 and 0 = 0
1 and 1 = 1

Xor:
0 xor 0 = 0
0 xor 1 = 1
1 xor 0 = 1
1 xor 1 = 0

Means 'A or B bot nor A and B' more or less... It can be applied to binary calculations but also to logical calculations. It means "exclusive or"


GfK(Posted 2008) [#8]
I do Not know what Xor does.
To clarify what Ziggy said in laymen's terms, imagine you have a number represented in binary:

%10101010

You can XOR that with another 8-bit pattern, for example, %00001111. The zeros mean that the corresponding bits of the number will not be touched. Anywhere there is a zero, will be inverted.

So:

%10101010 XOR %00001111, will become %10100101 (first four bits changed).

%10101010 XOR %00000001, will become %10101011 (only the first bit changed).

%10101010 XOR %11111111, will become %01010101 (all bits changed).

See?

You can use XOR for basic encryption. If you have Chr(97) (lower case 'a'):

97 as binary is %01100001.

Think of any old bit pattern - doesn't matter what. Let's use %00101101.

%01100001 XOR %00101101 = %01001100 = Chr(76) = upper case 'L'.

Performing the same operation on %01001100, with the same bit pattern (%00101101), returns the byte to its original value of 97.