Converting Dec word to Hex string


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003
    Location
    San Diego
    Posts
    35

    Question Converting Dec word to Hex string

    I have a word var that represents a 4 or5 digit decimal number... (00000 or 01234 example)
    I need to convert the var word to a string of 4 or 5 bytes that repsent the digits of the number.... example Dec Word var = 12345... result would be byte(0) = $35, Byte(1) = $ 34, Byte(2) = $33, Byte(3) = $ 32, Byte(4) = $31.
    I cannot pass through a serial port to do it so I have to do it another way.
    I have seen this before but cannot locate in a search.
    Tcbcats

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    digits var byte[5]
    x var byte
    y var word
    y = 12345
    
    for x = 0 to 4
    	digits[x]= (y dig x) +$30 ' find digit & convert to ASCII
    next x
    end
    ' digits[0]=$35
    ' digits[1]=$34
    ' digits[2]=$33
    ' digits[3]=$32
    ' digits[4]=$31
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

Similar Threads

  1. RF Modules
    By tonyfelloni in forum mel PIC BASIC Pro
    Replies: 44
    Last Post: - 26th June 2010, 18:42
  2. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 08:25
  3. DS2760 Thermocouple Kit from Parallax in PicBasicPro
    By seanharmon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th July 2008, 00:19
  4. PBPL 2.50 observations
    By BrianT in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 18th September 2007, 00:58
  5. calculation problem
    By nicolelawsc in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2006, 16:23

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