XOR woes


Closed Thread
Results 1 to 3 of 3

Thread: XOR woes

  1. #1
    Join Date
    Oct 2004
    Posts
    448

    Default XOR woes

    Hi, need some help, guys!

    I need to set a port to a certain value, depending on another variable which will have only 1 of 2 possible values, 0 or 255.

    For example, if the variable is 0, the port should output 45; if the variable is 255, the port should output its complement, 210.

    Now, I expected an XOR'ing of the 2 values to give the following results:

    0 XOR 45 = 45
    255 XOR 45 = 210

    However, what I get are pretty random results.

    I have tried both operators (XOR as well as ^), with no luck.

    Any idea what's happening?
    Last edited by Archangel; - 3rd February 2015 at 03:10.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: XOR woes

    Hi,
    You don't want to use the XOR operator, you want the ^ (bitwise XOR).
    Code:
    A VAR BYTE
    B VAR BYTE
    C VAR BYTE
    
    HSEROUT["Start",13]
    A = 0 : B = 45
    GOSUB Display
    
    A = 255 : B = 45
    GOSUB Display
    
    PAUSE 10
    END
    
    Display:
    C = A ^ B
    HSEROUT[DEC A, " ^ ", DEC B , " = ", DEC C,13]
    RETURN
    Gives
    Code:
    Start
    0 ^ 45 = 45
    255 ^ 45 = 210
    If it doesn't work at your end, please post the code.

    /Henrik.

  3. #3
    Join Date
    Oct 2004
    Posts
    448


    Did you find this post helpful? Yes | No

    Default Re: XOR woes

    Henrik, thanks for that. And sure, in its basic form the '^' operator works as expected.

    In this specific case, I realize that the complication(s)'s arisen because of the fact that the port being bit-manipulated has some pins which are inputs, and not to be controlled by the XOR.

    I'll need to mask off those bits, I guess.

    Thanks again

Similar Threads

  1. Logical difference between 2 8-bit ports XOR?
    By circuitpro in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd July 2010, 04:17
  2. XOR result different with PC application
    By Pic2008 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 26th January 2009, 04:56
  3. Xor?
    By skimask in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 12th October 2008, 06:13
  4. Xor Sum
    By Sphere in forum General
    Replies: 3
    Last Post: - 7th December 2006, 07:52
  5. Exclusive OR - XOR
    By Archangel in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th September 2006, 09:44

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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