Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Thread: Small xor tutorial.

  1. #1
    Join Date
    Feb 2006
    Posts
    1,022
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Small xor tutorial.

    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:

    SCAR Code:
    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.

    SCAR Code:
    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.

    SCAR Code:
    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

  2. #2
    Join Date
    Feb 2006
    Posts
    433
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

    Code:
    0010100  xor
    0100001 =
    0110101
    or like

    Edit: NVM

  3. #3
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    xor = or not (in SCAR, atleast), right?

    Nice tut, I'd almost forgotten about xor
    Interested in C# and Electrical Engineering? This might interest you.

  4. #4
    Join Date
    Feb 2006
    Posts
    1,022
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Smartzkid View Post
    xor = or not (in SCAR, atleast), right?

    Nice tut, I'd almost forgotten about xor
    Exclusive or, I think.

    Quote Originally Posted by Spky View Post
    Nice. You should explain how it really works, though (returns 1 if values are different, 0 if the same).

    Code:
    0010100  xor
    0100001 =
    0110101
    or like

    Edit: NVM
    Forgot about that part of it.

  5. #5
    Join Date
    Feb 2006
    Location
    Pennsylvania
    Posts
    1,524
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    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.

  6. #6
    Join Date
    Feb 2006
    Location
    With mooncow on the moon
    Posts
    292
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    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.
    ~ Solemn Wishes

  7. #7
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,691
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    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'.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  8. #8
    Join Date
    Feb 2006
    Posts
    1,022
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by solemn wishes View Post
    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.

  9. #9
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    I just recently learned this concept in PHP. =]

  10. #10
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    its still a nice tut
    ~Hermen

  11. #11
    Join Date
    Apr 2007
    Posts
    581
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    Nice :]
    I didnt even know xor was a command in SCAR.

  12. #12
    Join Date
    Feb 2006
    Posts
    1,022
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by ShawnjohnSJ View Post
    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 is highlighted and bold in SCAR. You could even use some!

  13. #13
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    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.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  14. #14
    Join Date
    Mar 2008
    Location
    The Netherlands
    Posts
    1,395
    Mentioned
    1 Post(s)
    Quoted
    1 Post(s)

    Default

    What to say, gravedig? 09-04-2007.. That's almost a year.


  15. #15
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    So what? Its helpful information. A gravedig is only when someone spams an old thread to the top, IMO.
    Interested in C# and Electrical Engineering? This might interest you.

  16. #16
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Oh, additionally, xor is almost (to my knowledge) the fastest computer operation.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  17. #17
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

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

  18. #18
    Join Date
    Jul 2007
    Posts
    0
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    cool thank you

  19. #19
    Join Date
    Nov 2008
    Posts
    55
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    nice tut

  20. #20
    Join Date
    Dec 2007
    Location
    Somewhere in Idaho
    Posts
    480
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by R0b0t1 View Post
    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)

    Quote Originally Posted by n3ss3s View Post
    (not(op1 xor op2)) == op1 and op2.
    Wrong. The truth tables for each look like this

    (xor)
    op1 op2 answer
    | 0 | 0 | 0
    | 0 | 1 | 1
    | 1 | 0 | 1
    | 1 | 1 | 0


    not (xor)
    op1 op2 answer
    | 0 | 0 | 1
    | 0 | 1 | 0
    | 1 | 0 | 0
    | 1 | 1 | 1

    and
    op1 op2 answer
    | 0 | 0 | 0
    | 0 | 1 | 0
    | 1 | 0 | 0
    | 1 | 1 | 1

    Clearly not xor is not equal to and

  21. #21
    Join Date
    Mar 2008
    Location
    ::1
    Posts
    915
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    I use xor to confuse people
    SCAR Code:
    someNumberThatWillEqualZero := MSCX xor MSCX;

    Records and Types Save Code (and make you look better)
    Quote Originally Posted by Wizzup? View Post
    Is it possible to make Runescape a 2D game with this?... That would greatly simplify... Just about anything.

  22. #22
    Join Date
    Feb 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks, I don't understand it much now, but it might help me later on.
    The lifeline of a scripter: newbbeginnerintermediateMasterLegend

  23. #23
    Join Date
    Dec 2007
    Location
    Los Angeles, California
    Posts
    606
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Cool code, not really used much as far as i know though .

    EDIT:

    LOL the day after i read this i need it in a script .
    Last edited by XRaye; 04-27-2009 at 09:53 AM.

  24. #24
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    If you are very interested, i inspected xor with 3 booleans


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

    EDIT: Btw, xor = ((a or b) and (not(a and b)))
    Last edited by marpis; 05-21-2009 at 11:56 PM.

  25. #25
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    gravedig...

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Making a Form Full-Screen (Small Tutorial)
    By Daniel in forum OSR Advanced Scripting Tutorials
    Replies: 19
    Last Post: 10-18-2008, 02:35 AM
  2. Help (only small)
    By poolikemax in forum OSR Help
    Replies: 5
    Last Post: 08-27-2008, 10:09 AM
  3. Small Help.
    By faster789 in forum OSR Help
    Replies: 11
    Last Post: 04-19-2008, 02:52 PM
  4. Replies: 8
    Last Post: 08-23-2007, 08:13 AM
  5. Array Tutorial - (Old Tutorial)
    By XxKanexX in forum Outdated Tutorials
    Replies: 1
    Last Post: 04-12-2006, 03:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •