Help putting a byte back together


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2007
    Posts
    59

    Default Help putting a byte back together

    Okay I'm stuck and need some help. In my program I am polling a port for settings from a dip switch which I'm breaking into 2 numbers. The first 4 and second 4 bits. the code is:

    ADDR = PortE ' Read Unit Address
    UID = ADDR >> 4 ' Shift Upper 4 Bits of into Lower 4 Bits
    LID = ADDR & %00001111 ' Mask-Off (set) Upper 4 Bits to Zero

    Now that I've separated the data I need at this point out of ADDR, I want to rebuild it (ADDR) using two different 4 bit numbers. So lets say I now have variables
    UID2 and LID2

    How do I shift UID2 from the lower to the upper Bits and then combine it with the lower bits of LID2.

    For example:
    UID2 = 00001011
    LID2 = 00001001
    I want ADDR to look like 10111001

    Thank you,
    Hylan

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    UID2 = UID2 << 4 ' shift nybble back to original location.
    LID2= UID2 | LID1 ' bitwise OR the two together.
    Charles Linquist

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Semantics, spelling, good beer, not sure.

    But maybe that should be, ...

    ADDR = (UID2 << 4) | (LID2 & $F)
    <br>
    DT

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Actually, a trip to the Sonoma area with little sleep afterward!
    Charles Linquist

  5. #5
    Join Date
    Sep 2007
    Posts
    59


    Did you find this post helpful? Yes | No

    Default

    Thank you. I'm learning slowly through trial, error, some more error, studying and trying. This forum has been an invaluable source of information.

Similar Threads

  1. LCD freeze
    By harryweb in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th October 2009, 08:01
  2. Memory use - how much do you use?
    By keymuu in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 10th June 2009, 22:39
  3. byte compression
    By Norbert in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th June 2007, 18:04
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. 16F877 RAM Question
    By Art in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 6th August 2005, 11:47

Members who have read this thread : 0

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