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 number
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Convert hex string to number [message #44341] Fri, 03 June 2005 13:43 Go to next message
Michael Wallace is currently offline  Michael Wallace
Messages: 409
Registered: December 2003
Senior Member
>> Assume you have a hexadecimal number stored as a string. How do you
>> convert this string to a numeric data type? I can easily convert a
>> number into a hex string, but how do you go the other way?
>>
>> -Mike
>
>
> I think you can use READS with the FORMAT keyword.

Yep. That is exactly what I was trying to find. Thanks. I knew that
it had to be in IDL somewhere, but I just couldn't figure out which
magic searches would take me to the right area of the documentation.
Re: Convert hex string to number [message #44342 is a reply to message #44341] Fri, 03 June 2005 13:26 Go to previous messageGo to next message
R.G. Stockwell is currently offline  R.G. Stockwell
Messages: 363
Registered: July 1999
Senior Member
"Michael Wallace" <mwallace.no.spam@no.spam.swri.edu.invalid> wrote in
message news:11a1dbmnro4e0f9@corp.supernews.com...
> Assume you have a hexadecimal number stored as a string. How do you
> convert this string to a numeric data type? I can easily convert a number
> into a hex string, but how do you go the other way?
>
> -Mike


IDL> s = 'f'

IDL> reads, s,out,format='(z)'

IDL> help,out

OUT FLOAT = 15.0000
Re: Convert hex string to number [message #44343 is a reply to message #44342] Fri, 03 June 2005 13:16 Go to previous messageGo to next message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
Michael Wallace wrote:
> Assume you have a hexadecimal number stored as a string. How do you
> convert this string to a numeric data type? I can easily convert a
> number into a hex string, but how do you go the other way?
>
> -Mike

I think you can use READS with the FORMAT keyword.

Benjamin
Re: Convert hex string to number [message #44566 is a reply to message #44342] Fri, 24 June 2005 15:02 Go to previous message
Michael Wallace is currently offline  Michael Wallace
Messages: 409
Registered: December 2003
Senior Member
>> Assume you have a hexadecimal number stored as a string. How do you
>> convert this string to a numeric data type? I can easily convert a number
>> into a hex string, but how do you go the other way?
>>
>> -Mike
>
>
>
> IDL> s = 'f'
>
> IDL> reads, s,out,format='(z)'
>
> IDL> help,out
>
> OUT FLOAT = 15.0000


It seems that when the hex numbers get so big, I start losing precision
on the conversion. I have tried a number of different ideas with the
format codes, but nothing has worked so far. It appears that reads
always stores the output value as a float despite how big the input
number is. Is there a way to for it to use double or long on the
conversion?

IDL> reads, '1234abcd', output, format = '(Z)'
IDL> print, output, FORMAT = '(I10)'
305441728
IDL> reads, '1234abce', output, format = '(Z)'
IDL> print, output, FORMAT = '(I10)'
305441728
IDL> reads, '1234abcf', output, format = '(Z)'
IDL> print, output, FORMAT = '(I10)'
305441728

Something is not right with the above picture...

-Mike
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: GeoTIFF tags and keys
Next Topic: Convert hex string to number

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

Current Time: Wed Oct 08 17:42:10 PDT 2025

Total time taken to generate the page: 0.00616 seconds