Re: converting 8 bytes to a double [message #2504] |
Wed, 03 August 1994 18:25 |
Geoff.Sobering
Messages: 14 Registered: June 1994
|
Junior Member |
|
|
In article <318lqdINN5n5@i32.sma.ch>, stl@sma.ch (Stephen Strebel) wrote:
> sorry about that. COnverting 4 bytes to a long (as in the lasting
> posting) isn't really what I wanted to find out about. I really need to
> convert 8 bytes into a double.
Should work the same as with byte->long.
new_double = double( existing_byte_array, 0, 1 )
and the reverse operation:
new_byte_array = byte( existing_double, 0, 8 )
--
Geoff Sobering (Geoff.Sobering@nih.gov)
In Vivo NMR Research Center
National Institutes of Health
|
|
|
Re: converting 8 bytes to a double [message #2535 is a reply to message #2504] |
Thu, 28 July 1994 09:36  |
sterner
Messages: 106 Registered: February 1991
|
Senior Member |
|
|
stl@sma.ch (Stephen Strebel) writes:
> Hi again,
> sorry about that. COnverting 4 bytes to a long (as in the lasting
> posting) isn't really what I wanted to find out about. I really need to
> convert 8 bytes into a double.
> Any ideas? Or any libraries that already do this?
What you want to do is called field extraction and is discussed
in Chapter 4 of the IDL User's Guide in the secion on
Type Conversion Functions.
If you have a byte array b you can extract doubles from it as follows:
d = double(b,s,n)
where s is the starting element in array b, and n is the number
of doubles to extract. n is actually the size of the first dimension
of the extracted array and could be followed by other dimensions to
extract multidimensional arrays.
An example:
a=dblarr(5)+!dpi ; Create a 5 element double array.
b=byte(a,0,8,5) ; Convert it to an 8 x 5 byte array.
print,b ; Look at it.
64 9 33 251 84 68 45 24
64 9 33 251 84 68 45 24
64 9 33 251 84 68 45 24
64 9 33 251 84 68 45 24
64 9 33 251 84 68 45 24
print,double(b,0,5) ; Extract & print the original values.
Ray Sterner sterner@tesla.jhuapl.edu
Johns Hopkins University North latitude 39.16 degrees.
Applied Physics Laboratory West longitude 76.90 degrees.
Laurel, MD 20723-6099
|
|
|