Hi,
I am trying to figure out how to convert a decimal number to it's Ascii equivalent. If I have a number say 1432345 I want to convert it to 31 34 33 32 33 34 35
Does anyone know a easy way to do this ?
Any help would be greatly appreciated.
thanks
Decimal To ASCII
Moderators: David Barker, Jerry Messina
- David Barker
- Swordfish Developer
- Posts: 1214
- Joined: Tue Oct 03, 2006 7:01 pm
- Location: Saltburn by the Sea, UK
- Contact:
There are a number of ways to do this, here is one...
Code: Select all
Include "utils.bas"
Include "usart.bas"
Include "convert.bas"
Dim Value As Byte
SetBaudrate(br115200)
Value = Digit(1432345,2) + $30
USART.write("$", Hextostr(value),13,10)
Hi Dave,
Thanks for the reply, but I am trying to convert the other way. I have a string of numbers say "1407123" and I want to convert each digit to a ASCII equiv. 1 = 31, 4 = 34, 0 = 30, 7 = 37, 2 = 32, 3 = 33
Maybe I am not seeing the clear picture here, but I can't seem to find a way to parse the string and get the charcter I want to determine what the ASCII value would be. Any help would be appreciated.
Thanks
Thanks for the reply, but I am trying to convert the other way. I have a string of numbers say "1407123" and I want to convert each digit to a ASCII equiv. 1 = 31, 4 = 34, 0 = 30, 7 = 37, 2 = 32, 3 = 33
Maybe I am not seeing the clear picture here, but I can't seem to find a way to parse the string and get the charcter I want to determine what the ASCII value would be. Any help would be appreciated.
Thanks
- David Barker
- Swordfish Developer
- Posts: 1214
- Joined: Tue Oct 03, 2006 7:01 pm
- Location: Saltburn by the Sea, UK
- Contact:
That's easier...
or
This will display the values...
Code: Select all
dim Ch as char
Ch = Str(index)
Code: Select all
dim Value as byte
Value = byte(Str(index))
Code: Select all
Include "usart.bas"
Include "convert.bas"
dim Str as string
dim Index, Value as byte
SetBaudrate(br115200)
Str = "1407123"
index = 0
while Str(index) <> null
Value = byte(Str(index))
USART.Write("$", HexToStr(Value) ,13,10)
inc(index)
wend