Literal Hex to ASCII Conversion
TurnipTruck
Junior Member
Greetings,
I am trying to translate a literal hex string to the ASCII characters it represents.
Example: '46726F6E74' needs to be translated to 'Front'
I have looked at FORMAT, HEXTOI, etc with no luck.
Any thoughts?
Thanks.
I am trying to translate a literal hex string to the ASCII characters it represents.
Example: '46726F6E74' needs to be translated to 'Front'
I have looked at FORMAT, HEXTOI, etc with no luck.
Any thoughts?
Thanks.
Comments
-
I don't know a ready-to-use programming instruction which will do this.
Assuming a single byte is represented always with 2 characters, only a self made function may do this.DEFINE_FUNCTION CHAR[15] AsciiHexToBytes(CHAR sStr[30]) { STACK_VAR CHAR sByteAscii[2] STACK_VAR CHAR sHexString[15] // the output string STACK_VAR INTEGER nByteCount // how much real bytes STACK_VAR INTEGER nX // for the FOR loop nByteCount = LENGTH_STRING(sStr) / 2 // how much "real" Bytes are there FOR(nX=1;nX<=nByteCount;nX++) { sByteAscii = GET_BUFFER_STRING(sStr,2) sHexString = "sHexString,HEXTOI(sByteAscii)" } RETURN sHexString }
If the byte values are matching the ASCII table, you'll get your "Text".
Should do that - theoredically
. Don't have a master to test at the moment..... -
ITOA(HEXTOI(strHexString))
-
Or if you are getting it in as comma seperated hex values, just bung it in a char array.
-
Hm....yuri wrote:ITOA(HEXTOI(strHexString))
HEXTOI('3132') -> 12594
ITOA(12594) -> '12594'
But if handling that 4 chars '3132' as "2 bytes" (what my function above may do), the result of the function is " '12' "
Other example:
HEXTOI('595A') -> 22874
ITOA(22874) -> '22874'
But the function result may be " 'YZ' " -
I'd worry about exceeding the maximum integer size if I were doing HEXTOI on the whole thing. Marc's function seems like the way to go.
-
i will post three
next time to denote the amount of sarcasm
-
umm... lol?yuri wrote:i will post three
next time to denote the amount of sarcasm 
-
Thank you Marc and others. I will code up the function that Marc suggests and see what happens. I did something similar in the past, but it resulted in compiler warnings.
-
yuri wrote:i will post three
next time to denote the amount of sarcasm 
Ok, don't see my message as "I have not seen the sarcasm" but as "I just wanted to show what's the difference for those who are interested" (n+1
) -
Back on topic here......
The HEXTOI conversion works well. It may be recommended that the string which will hold the converted value not have its type defined. If declared as a CHAR array, you may get a compiler warning when you try to put an integer value into it.
DEFINE_VARIABLE
CHAR cORIGINAL_STRING[32]
cCONVERTED_STRING[16]
Thank you for your help. -
TurnipTruck wrote:Back on topic here......
The HEXTOI conversion works well. It may be recommended that the string which will hold the converted value not have its type defined. If declared as a CHAR array, you may get a compiler warning when you try to put an integer value into it.
DEFINE_VARIABLE
CHAR cORIGINAL_STRING[32]
cCONVERTED_STRING[16]
Thank you for your help.
Not declaring a type is the same as flat -out declaring it INTEGER; that's the default variable type. Maybe I'm just being nit-picky here, but if your problem is assigning an integer value to an array position that really ought to have a CHAR, you should fix it on the other end rather than making an integer array. TYPE_CAST() is made for just such situations as this.
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums