comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: convert hex string to ascii
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: convert hex string to ascii [message #53366 is a reply to message #53362] Sat, 07 April 2007 11:41 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"metachronist" <rkombiyil@gmail.com> writes:
> Dear list members,
>
> Sorry to bother with a trivial (?) question.. I was wondering if there
> is a way to convert a hex byte string to corresponding ascii string?
> i.e., 'ABC ' would be coded as:41424320 (long int), I need to convert
> this back as ascii..
> What I did was to read in the corresponding long integer
> representation and then use the "Z" format specifier to get the hex
> representation and look up the "ASCII" table for the characters. But
> in this case, the order in which these (ascii characters comprising
> the string) appear reversed (?!, i.e., 'ABC ' as ' CBA'), which I
> suspect is due to the way hex is computed from its corresponding
> binary representation?
>
> I am confused. Any suggestions / where can I find some examples to
> clear up this hex muddle in my head? :-(

I would have decoded your actual data to a string with,
data = '41424320'xl
str = string(byte(data,0,4))

However, your real problem is an "endian" (byte-order) problem. For
example, the integer '41424320'xl can be stored in two different byte
strings, depending on the CPU architecture. You need to find out what
endianness your data was encoded with, and what endianness your
computer is. In all likelihood you can use BYTEORDER to fix the
problem. A more brutish solution could be achieved with REVERSE() in
the expression above.

Good luck,
Craig

P.S. On my Mac, STR = 'ABC '. On my PC, STR = ' CBA'

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Previous Topic: Re: significance of a linear regression
Next Topic: counting rows

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 05:17:21 PDT 2025

Total time taken to generate the page: 0.80095 seconds