PDA

View Full Version : Converting Dec word to Hex string



tcbcats
- 28th August 2007, 05:19
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

paul borgmeier
- 28th August 2007, 05:44
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