XOr?

Monkey Forums/Monkey Programming/XOr?

NoOdle(Posted 2012) [#1]
Just looking at implementing bitboards and couldn't find an XOR? I must admit I have never done bitwise manipulation so I have probably missed something.

Also if anyone can recommend any beginner reading on bitwise magic then I would be most grateful, my current searches aren't proving very useful.


NoOdle(Posted 2012) [#2]
Oops, language -> expressions. I should have looked a bit more closely...


NoOdle(Posted 2012) [#3]
hmm a logical right shift could be handy...


ziggy(Posted 2012) [#4]
logical right shift? I don't see any reasonable usage for this, there is a bitwise right shift "shr"


NoOdle(Posted 2012) [#5]
I stumbled across a tutorial that used it and I was curious to play around with it to see the results. I am just starting to learn all of this, something I should have done years ago tbh so I don't know what uses the operations have yet..


AdamRedwoods(Posted 2012) [#6]
the exlusive-or "xor" or "~" in monkey, is used in assembly language to reset a register. you just xor the register with itself to set it to zero. It can also be used to flip the value of a flag register.

It is also used during conversations with women when they want to know if they can call you a "boyfriend". As in.. "are we exclusive or...?" :D


NoOdle(Posted 2012) [#7]
Thanks Adam I'm starting to understand the uses. I think I need to spend a few days learning assembly language. Might as well start at the beginning.

It is also used during conversations with women when they want to know if they can call you a "boyfriend". As in.. "are we exclusive or...?" :D

lol I like that.

you just xor the register with itself to set it to zero. It can also be used to flip the value of a flag register.


	Local r : Int = 32
	r = ~ r
	Print r

outputs -33. performing r = ~r for a second time reverts the number to its original; 32.

	Local r : Int = 32
	r = r ~ r
	Print r

outputs 0 as you suggested. Interesting... and potentially very useful. Really wish I had tackled this stuff 15 years ago when I was younger!


Jesse(Posted 2012) [#8]
actually that is a "not" not an xor

this is how xor is supposed to work:
http://www.xcprod.com/titan/XCSB-DOC/binary_xor.html

this are bitwise operations:
http://en.wikipedia.org/wiki/Bitwise_operation


NoOdle(Posted 2012) [#9]
Thanks I'm currently reading these now. How do you do xor in monkey, the language->expressions page says ~ bitwise 'xor' is this right or?


Jesse(Posted 2012) [#10]
I think that Mark has it working so that when you use the ~ with a single number you get a not
and when you combine a number "~" and a number it works as xor. you can't do that with the other operators.

this is a not (~n)
this is an xor (n~p)


NoOdle(Posted 2012) [#11]
Yea! I was just about to edit my post, I checked out the online bitwise calculator from the wiki link and noticed it required two numbers, I then twigged and understood what you meant.


Gerry Quinn(Posted 2012) [#12]
It's good to know a bit about assembly language, to help you have a feel for what will be fast or slow. But you don't need to actually use it since about 1990!