XOr?
Monkey Forums/Monkey Programming/XOr?
| ||
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. |
| ||
Oops, language -> expressions. I should have looked a bit more closely... |
| ||
hmm a logical right shift could be handy... |
| ||
logical right shift? I don't see any reasonable usage for this, there is a bitwise right shift "shr" |
| ||
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.. |
| ||
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 |
| ||
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! |
| ||
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 |
| ||
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? |
| ||
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) |
| ||
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. |
| ||
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! |