Thread: XOR explanation...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    11

    XOR explanation...

    I have been playing around with XOR and I'm just curious as to how it works. I don't mean the TRUTH Table thing. Here's an example. A and B characters have an ascii value of 65 and 66 respectively. When A XOR B the ascii value is 3(or vice versa). Why is the number 3? What goes on behind the scenes there? Thanks.

    -CDudd

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    It's pretty interesting... I wondered about that for a while too. Pretty much this is what happens, assuming you are using, say, a 1-byte variable (char, for example).

    Say you have the values A (23) and B (45), this is what it looks like:
    Code:
    bit      1 2 3 4 5 6 7 8    //memory locations
    value A  0 0 1 0 1 1 0 1    //how 45 is represented
    value B  0 0 0 1 0 1 1 1    //how 23 is represented
    ------------------------------   ---XOR---
    value C  0 0 1 1 1 0 1 0    //the result, or 58.
    I'm not sure about how the bits are numbered, I might have them backwards (i.e. it's 8,7,6,5,4,3,2,1 instead of the other way around), but that's pretty much the idea... Oh, and by the way, was that what you were asking?
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    11
    You nailed it!! That's what I suspected, but I just wasn't sure. Thanks for clearing that up. I just don't like things to be black boxes, if you know what I mean .


    -CDudd

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    No problem, I know exactly what you mean
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed