1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

XOR function

Discussion in 'Microcontrollers' started by Zaeed, Apr 22, 2009.

  1. Zaeed

    Zaeed New Member

    Joined:
    Apr 19, 2009
    Messages:
    22
    Likes:
    0
    Hi, I'm trying to perform a checksum on my RFID tag. I have an array with the 5 bytes that make up my RFID and a 6th that is the checksum.

    I have to XOR the 5 bytes and check if they equal the 6th..

    How do I do this? I can't figure it out

    Thanks
     
  2. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,019
    Likes:
    317
    Location:
    Brisbane Australia
    Just XOR all 6 bytes together and the result should be zero.

    Mike.
     
  3. Zaeed

    Zaeed New Member

    Joined:
    Apr 19, 2009
    Messages:
    22
    Likes:
    0
    But what is the code to do this?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. felis

    felis New Member

    Joined:
    May 30, 2006
    Messages:
    190
    Likes:
    2
    Location:
    Colorado


    Depends on a language. That's how it would look in Fortran:
    Code (text):

    XOr(I, J)
     
    Which one are you using?
     
  6. Zaeed

    Zaeed New Member

    Joined:
    Apr 19, 2009
    Messages:
    22
    Likes:
    0
    I'm using C18
     
  7. felis

    felis New Member

    Joined:
    May 30, 2006
    Messages:
    190
    Likes:
    2
    Location:
    Colorado
    in C, the operator is ^. To XOR a and b you write:
    Code (text):

    a = a^b;
     
    or
    Code (text):

    a ^= b;
     
     
    Last edited: Apr 23, 2009
  8. Zaeed

    Zaeed New Member

    Joined:
    Apr 19, 2009
    Messages:
    22
    Likes:
    0
    Cheers for that.
     

Share This Page