Results 1 to 15 of 15

Thread: Xor?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    Question

    What XOR do? And how can it be used?

  2. #2
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    I posted a checksum function that uses the xor operator in one of your threads, by using xor I prevent the value of the checksum surpassing 255.

    It is used to check if one bit or the other bit is set, but not both.

    so if I had bit 1 set in a byte, and the bit 1 set in another byte and I compared them with xor, I would get 0 as they are both set on.
    Last edited by JamesM; Apr 19th, 2001 at 12:33 AM.

  3. #3
    Chavez
    Guest
    Here is MSDN's help file on it.
    Attached Files Attached Files

  4. #4
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    To see what is happening try:

    Code:
    Private Sub Command1_Click()
    Dim b1 As Byte, b2 As Byte
    b1 = 0
    b2 = 16
    
    MsgBox b1 Xor b2 ' = 16 As bit 5 is Set In only one
    
    End Sub
    
    
    Private Sub Command1_Click()
    Dim b1 As Byte, b2 As Byte
    b1 = 16 'bit 5 Set
    b2 = 16 'bit 5 Set
    
    MsgBox b1 Xor b2 '0 As bit 5 is Set In both
    
    End Sub

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    OK..

    Then how come this returns 7

    Code:
    Dim b1 As Byte, b2 As Byte
    b1 = 1 'bit 5 Set
    b2 = 6 'bit 5 Set
    
    MsgBox b1 Xor b2 '0 As bit 5 is Set In both
    shouldnt it return 0?

  6. #6
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    This is why

    1 is 00000001 in binary (bit 1 set only)

    6 is 00000110 in binary (bit 2 and 3 set)

    1 xor 6 = 00000111 in binary which equals 7 decimal !

    See, xor checks the equivalent bits and returns 1 where either of the bits is set but not both.

  7. #7
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    image operations, checking for keypresses, making flags, etc.
    (its how you can have vbyesno and vbcritical passed together in a msg box)
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  8. #8
    Dreamlax
    Guest
    If you and 2 numbers (or or them) is there a way to get them apart again? I haven't got my 'thinking cap' on today.

  9. #9
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    no.
    the only one you can separate again is the XOR,
    and thats if you know one of the # already.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  10. #10
    Dreamlax
    Guest
    Now it makes sense, I suppose it's like you converting 30 back into it's two original factors I was thinking of.

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    no one mentioned what xor is

    xor stands for exclusive or and is a boolean logic comparation operator defined as:

    P != q = (¬p ^ q) v (p ^ ¬q)

    and is analogous with <> operator for aritmetical comparations.

    true xor false is true
    false xor true is true
    false xor false is false
    true xor true is false

    boolean xor operator should not be mixed with the bitwise xor operator, which is used to compare bits of aritmetical numbers.
    Last edited by kedaman; Apr 20th, 2001 at 02:34 AM.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  12. #12
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: no one mentioned what xor is

    Originally posted by kedaman
    true xor false is false
    false xor true is false
    false xor false is false
    true xor true is false
    Hmm So if you use Xor, it always returns false? Looks like a typo to me
    false xor true = true
    true xor false = true
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  13. #13
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    yeah sorry
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  14. #14
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    You can make xor out of and and or:
    (x or y) and not (x and y)

    Code:
    Private Sub Command1_Click()
    Dim x As Integer
    x = 7
    MsgBox x Xor 1
    MsgBox (x Or 1) And Not (x And 1)
    End Sub

  15. #15
    gs1111
    Guest

    Talking To X or Not To X or ......

    In the 70's when memory was really expensive, it was a challenge to get most out of a given amount of RAM or whatever storage one was using. Consequently, the art of XOR 'ing and ANDOR'ing needed to be mastered, just so that a problem could be solved. You probably understand that XOR/ANDOR allows one to flip the bits in a byte in a logical manner so as to acheive a new status or value within the byte. Logically, a byte can store 8 bits ON or OFF, so in simple terms, we can store up to 8 switch values or True/False values in a single byte - WOW!!!!
    Now that we have arrived in 2001, the instruction capability remains in the languages, but the need to apply the instructions is not entirely relevant today. (Saving a few bytes is not the name of the game any more, rather, understandable, preferably self documenting code is the way of success in a piece of software). So, are you an academic or are you a worker?
    Understand and explore the world of bits if you must, but do it in your own time - a company employing you will not thank you for the wonders you can acheive with XOR/ANDOR (unless they are trying to fit a massive application on the face of a 4k Chip).
    And do spare a thought for those who follow - they may need to fix some problem you create, and working in the underworld of bits ain't much joy.
    I do admire some dedicated developers who use the technique of XOR/ANDOR through a controlable subroutine, to acheive massive arrays of switches. Suggest you visit www.Softcircuits.com where you will find one such piece of code.

Posting Permissions

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



Click Here to Expand Forum to Full Width