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

Home » Public Forums » archive » 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
Convert hex string to number [message #44344] Fri, 03 June 2005 12:54 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
Re: Convert hex string to number [message #44564 is a reply to message #44344] Fri, 24 June 2005 15:29 Go to previous message
Michael Wallace is currently offline  Michael Wallace
Messages: 409
Registered: December 2003
Senior Member
Karl Schultz wrote:
> On Fri, 24 Jun 2005 17:02:12 -0500, 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
>>>
>>>
>>>
>>> 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
>
>
> Docs say:
>
> Note
> If the variable specified for the Vari argument has not been previously
> defined, the input data is assumed to be of type float, and the variable
> will be cast as a float.
>
> So,
>
> output = 1d
>
> before you call READS does the trick.
>
> Karl


Wow. And to think I stared at the reads documentation for so long today
and just missed it. Thanks.

-Mike
Re: Convert hex string to number [message #44565 is a reply to message #44344] Fri, 24 June 2005 15:23 Go to previous message
Karl Schultz is currently offline  Karl Schultz
Messages: 341
Registered: October 1999
Senior Member
On Fri, 24 Jun 2005 17:02:12 -0500, 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
>>
>>
>>
>> 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

Docs say:

Note
If the variable specified for the Vari argument has not been previously
defined, the input data is assumed to be of type float, and the variable
will be cast as a float.

So,

output = 1d

before you call READS does the trick.

Karl
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Convert hex string to number
Next Topic: Re: Different scales in the same plot

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

Current Time: Wed Oct 08 17:44:55 PDT 2025

Total time taken to generate the page: 0.00495 seconds