Need help converting a 4 bit binary number to 4 separate values


Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427

    Default Need help converting a 4 bit binary number to 4 separate values

    Hey group,
    I am trying to build a Decimal / Hex / Binary number demonstrator to teach electronics and microcontrollers to a bunch of Scouts (the Electronics merit badge is what I am teaching)

    I am stuck on the following problem... (and running out of time before the upcoming class)

    If I have a number x (from 0 to 15)
    I need to set variables d,c,b,a to the binary representation of the 4 digit positions of x.

    so if x = 8 which is %1000 in binary
    then...
    a should =0
    b should =0
    c should =0
    d should =1

    so if x = 9 which is %1000 in binary
    then...
    a should =1
    b should =0
    c should =0
    d should =1

    I have tried (with no success) many different methods including arraywrite and bin string modifiers but they are all failing.

    I have tried a 4 byte array
    I have tried trying to select each digit in the 4 bit binary number

    I know there is a way I just can't get to it (yet)

    My final purpose is to write each of the 4 digit positions to a I2C 4-digit 7-segment display, I need to be able to write each digit to its position 0-3 separately.

    Any Ideas or guidance would be greatly appreciated.

    My code is just a mess right now
    here is a NON WORKING partial
    Code:
            i2cwrite sda,scl,$e0,0,[bin1 x]
            i2cwrite sda,scl,$e0,1,[b]
            i2cwrite sda,scl,$e0,2,[c]
            i2cwrite sda,scl,$e0,3,[d]
    How do I select a given digit from within a 4 bit number and send just that digit to the I2C display??
    I guess I may have to resort to some sort of look up table for each of the 4 digit positions.

    thanks
    Last edited by Heckler; - 22nd June 2015 at 03:30.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

Similar Threads

  1. Replies: 10
    Last Post: - 8th March 2015, 19:26
  2. Changing output binary number sequence? is it possible?
    By wdmagic in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd January 2013, 00:47
  3. Replies: 7
    Last Post: - 11th September 2010, 00:32
  4. Convert long binary number to ASCII Decimal
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 9th July 2009, 13:58
  5. Averaging 16 bit values without using 32 bit math
    By sirvo in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th October 2007, 22:18

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