Can anyone help me with the code to construct a ascii string?
As an example there are 10 consecutive bytes held in program memory as follows:
30 34 31 35 44 38 42 31 39 37
These in ASCii are: 0415D8B197
I would like to take these 10 Hexadecimal numbers and create an ASCii string like: Str_Var = "0415D8B197"
I have tried the Conversion module but there is no HexToAscii available.
Any help would be appreciated.
Thanks
SamB
Help with Ascii string
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 is no such conversion function because a hex number and ascii are the same, as the following shows:
so if you are reading a byte, typecast to char for string manipulation.
Code: Select all
include "usart.bas"
dim str as string
str = char($30) + char($34) + char($31)
usart.SetBaudrate(br19200)
usart.write(str,13,10)
Thank you Dave.. It does work but I am still a little confused.
After I asked for help in this forum I came up with a work-around because to continue with my code I needed this function.
You mentioned that "a hex number and ascii are the same' but then why did my work-around do the same thing as your 'Type Casting' solution?
Just wondering...
After I asked for help in this forum I came up with a work-around because to continue with my code I needed this function.
You mentioned that "a hex number and ascii are the same' but then why did my work-around do the same thing as your 'Type Casting' solution?
Code: Select all
For Index = 0 To 9
Byte_Var = Mem.ReadByte(TTA + (10 * Count) + Index)
If Byte_Var >= $30 And Byte_Var <= $39 Then
Byte_Var = Byte_Var - $30
Else
Byte_Var = Byte_Var - $37
EndIf
UserTag = UserTag + HexToStr(Byte_Var)
Next 'Index
If UserTag = TagNum Then
Result = errOK
- David Barker
- Swordfish Developer
- Posts: 1214
- Joined: Tue Oct 03, 2006 7:01 pm
- Location: Saltburn by the Sea, UK
- Contact: