PDA

View Full Version : Small xor tutorial.

The Un-Named
08-29-2007, 12:55 PM
Ok, not really super advanced, or useful for that matter, but it can easy fit in with a failsafe proc.

Ok, so lets begin, xor is a keyword, used pretty much the same as or. But, there's a difference, lets take the following script for example:

var
a : Integer;

begin
a := 5;
if ( a > 2) or
( a < 6 ) then
Writeln('a is either more than 2, less than 6, or even both!');
end.

Simple, if a is either more than 2, less than 6 or both, then it will write a string to the debug box. But lets say, we ONLY wanted to write to the debug box if only ONE condition was met? This is where xor comes into play.

var
a : Integer;

begin
a := 5;
if ( a > 2) xor
( a < 6 ) then
Writeln('a is either more than 2, or less than 6.');
end.

If you've been paying attention, you'll know that this doesn't print anything, change "( a < 6 ) then" to "( a < 4 ) then" and Bob's your uncle.

You can also mix it with the other operators such as and, or.

var
a : Integer;

begin
a := 5;
if ( a > 2) and
( a < 6 ) xor
not( a = 5 ) then
Writeln('if a is more than 2, and either less than 6, or not 5, then print!');
end.

Have fun. :P

Spky
08-29-2007, 01:57 PM
Nice. You should explain how it really works, though (returns 1 if values are different, 0 if the same).

0010100 xor
0100001 =
0110101or like

Edit: NVM:p

Smartzkid
08-29-2007, 02:10 PM
xor = or not (in SCAR, atleast), right?

Nice tut, I'd almost forgotten about xor

The Un-Named
08-29-2007, 03:16 PM
xor = or not (in SCAR, atleast), right?

Nice tut, I'd almost forgotten about xor

Exclusive or, I think.

Nice. You should explain how it really works, though (returns 1 if values are different, 0 if the same).

0010100 xor
0100001 =
0110101or like

Edit: NVM:p

Forgot about that part of it. :o

Bebe
08-29-2007, 03:26 PM
This isn't really that advanced :P

I only used xor once when I was creating a password generator, though. But that was back on kaits.

solemn wishes
08-29-2007, 07:28 PM
sorry but i fail to see why this has been posted in the advancted section. Thankyou for sharing but this should definatly be in beginners, as many of the beginner tutorials show this information.

Wizzup?
08-29-2007, 07:34 PM
Exclusive Or, yes.

I only learnt what xor, shr and shl were after I got very annoyed by reading Ben's code who knew more 'bold programming thingies'. :p

The Un-Named
08-29-2007, 09:40 PM
as many of the beginner tutorials show this information.

I only posted it because I've never saw anyone post it before. But yeah, I agree, it's not super advanced like you and me say, but I felt it'd be better here so people who probably could use it will.

There's only one place I think it could really be used, in the fishing guild to see if both docks are on the screen, (do a xor on searching for bitmaps or dtms of both docks) to determine if your in the bank if it's lets say, ridiculously crowded and no hopes of finding the symbol.

lordsaturn
09-03-2007, 03:59 AM
I just recently learned this concept in PHP. =]

ShowerThoughts
09-03-2007, 12:01 PM
its still a nice tut;)

ShawnjohnSJ
09-03-2007, 12:25 PM
Nice :]
I didnt even know xor was a command in SCAR.

The Un-Named
09-03-2007, 11:59 PM
Nice :]
I didnt even know xor was a command in SCAR.

There's a lot more, but a lot of "un-used ones" that can't be used fully in SCAR, probably every one on this page (http://www.umanitoba.ca/campus/acn/unix/software/vendor_html/gpc/gpc_517.html) is highlighted and bold in SCAR. You could even use some!

R0b0t1
07-18-2008, 09:51 PM
There are already binary operator tutorials, aren't there?

Oh, and theres also xnor, which: (not(op1 xor op2)). I've used it before. Returns true if not 1,0; 0,1.

Laurâ‚¬ns
07-23-2008, 01:59 PM
What to say, gravedig? 09-04-2007.. That's almost a year.

Smartzkid
07-24-2008, 01:28 AM
So what? Its helpful information. A gravedig is only when someone spams an old thread to the top, IMO.

R0b0t1
07-30-2008, 01:25 AM
Oh, additionally, xor is almost (to my knowledge) the fastest computer operation.

n3ss3s
08-05-2008, 07:05 AM
(not(op1 xor op2)) == op1 and op2.

iseedcuk
08-21-2008, 09:36 PM
cool thank you

hutic
11-17-2008, 01:47 AM
nice tut

boberman
11-17-2008, 06:44 AM
Oh, additionally, xor is almost (to my knowledge) the fastest computer operation.

mhh, not really, and, nand, or, nor will all be on the same order of speed. Last I read nand gates where the fastest. However for any single bit operations you are going to see about the same speed. The Inc operation is also pretty dang fast when you get down to the gate level of how it is implemented.

The thing is how fast a gate toggles really doesn't matter all that much. Every gate will operate within a clock cycle, so doing an bitwise and or a bitwise xor will show no difference at all. Clock cycles where introduced for good reasons, however their end result is that your computer can only operate at the speed of its slowest gate (Which, btw, they tend to use mostly nand gates as you can make all the other gates out of a couple of nand gates)

(not(op1 xor op2)) == op1 and op2.

Wrong. The truth tables for each look like this

(xor)
| 0 | 0 | 0
| 0 | 1 | 1
| 1 | 0 | 1
| 1 | 1 | 0

not (xor)
| 0 | 0 | 1
| 0 | 1 | 0
| 1 | 0 | 0
| 1 | 1 | 1

and
| 0 | 0 | 0
| 0 | 1 | 0
| 1 | 0 | 0
| 1 | 1 | 1

Clearly not xor is not equal to and

Tniffoc
03-31-2009, 05:33 AM
I use xor to confuse people :)

eruption144
04-10-2009, 12:26 PM
Thanks, I don't understand it much now, but it might help me later on. :)

XRaye
04-26-2009, 07:30 AM
Cool code, not really used much as far as i know though :p.

EDIT:

LOL the day after i read this i need it in a script :p.

marpis
04-28-2009, 12:34 AM
If you are very interested, i inspected xor with 3 booleans
http://img.photobucket.com/albums/v607/m47145/xortable.png

OH didnt notice this was so old conversation. Well, i hope someone seems my kewl table :D i spent 5 valuable minutes doing it

EDIT: Btw, xor = ((a or b) and (not(a and b)))

Kasi
04-28-2009, 01:25 AM
gravedig...

Wizzup?
04-28-2009, 02:07 AM
So what? Its helpful information. A gravedig is only when someone spams an old thread to the top, IMO.

...

Da 0wner
04-29-2009, 09:56 AM
Besides, there is not many threads to bump it over anyway.

ian.
04-30-2009, 07:41 AM
...

D:< Is Wizzup? mad or agreeing? >.> I DON'T KNOW ANYTHING ANYMORE!

DAMN YOU!

:norris:

And marpis, I loved the table ;D