HEX numbers


Closed Thread
Results 1 to 4 of 4

Thread: HEX numbers

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

    Default HEX numbers

    Is there an easy way to separate the "digits" of a hex number?
    For example 63251 = F713, but I need to separate out each digit
    as ASCII into an array element.
    e.g.

    NumArray[0] = "F"
    NumArray[1] = "7"
    NumArray[2] = "2"
    ...

    I know there must be an elegant way, but I can't think of it.
    Charles Linquist

  2. #2
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Try this link.

    Regards

    Sougata

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    I don't know if it is elegant but ...

    X var WORD
    Y var BYTE
    NumArray var BYTE[4]

    X = 63251

    Y = X.lowbyte & $0F ' isolate the lower nibble
    gosub ConvertAscii
    NumArray[3]=Y ' ="3"

    Y = X.lowbyte >> 4 ' move high nibble to low nibble
    gosub ConvertAscii
    NumArray[2]=Y '="1"

    Y = X.highbyte & $0F ' isolate the lower nibble
    gosub ConvertAscii
    NumArray[1]=Y '="7"

    Y = X.highbyte >> 4 ' move high nibble to low nibble
    gosub ConvertAscii
    NumArray[0]=Y '="F"

    END

    ConvertAscii:
    If Y < 10 then
    Y = Y + 48
    Else
    Y = Y + 55
    Endif
    Return

    Good Luck,

    Paul Borgmeier
    Salt Lake City, Utah
    USA
    Last edited by paul borgmeier; - 16th April 2006 at 07:54.

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


    Did you find this post helpful? Yes | No

    Default

    After I posted I realized that I had the answer all along. I wrote an Intel Hex routine awhile back. It dealt with bytes only. All I had to do was to use the routine twice - very similar to your approach.

    Thanks for responding!
    Charles Linquist

Similar Threads

  1. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  2. Configuration bits in a HEX file gone missing?
    By grzes.r in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd February 2010, 01:10
  3. PIC16F877A pwm use for IR transmission
    By mcbeasleyjr in forum General
    Replies: 0
    Last Post: - 11th July 2009, 18:51
  4. Replies: 4
    Last Post: - 15th April 2009, 01:54
  5. Splitting numbers and recombining them(EEPROM Error)
    By selbstdual in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd June 2007, 06:40

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