8 byte to double? [message #92599] |
Wed, 20 January 2016 04:39  |
LNpellen
Messages: 37 Registered: November 2009
|
Member |
|
|
I'm lost - and I thought I had solved this previously, but I simply can't find it (maybe it was in php or something...).
Some values in the DICOM header for some vendors happens to save floating (double-presition?) values as 8-bytearrays
Is there a simple way in IDL to convert this bytearray to a double without coding the type conversion yourself?
I couldn't manage to use the DOUBLE function for this.
Ex.:
I have the byte array [205 204 204 204 204 204 49 64] and it think from my annoyingly short notes that it should be 17.8...?
Best regards,
Ellen
|
|
|
Re: 8 byte to double? [message #92600 is a reply to message #92599] |
Wed, 20 January 2016 04:58   |
Lajos Foldy
Messages: 176 Registered: December 2011
|
Senior Member |
|
|
On Wednesday, January 20, 2016 at 1:39:07 PM UTC+1, LNpellen wrote:
> I'm lost - and I thought I had solved this previously, but I simply can't find it (maybe it was in php or something...).
>
> Some values in the DICOM header for some vendors happens to save floating (double-presition?) values as 8-bytearrays
>
> Is there a simple way in IDL to convert this bytearray to a double without coding the type conversion yourself?
>
> I couldn't manage to use the DOUBLE function for this.
>
> Ex.:
> I have the byte array [205 204 204 204 204 204 49 64] and it think from my annoyingly short notes that it should be 17.8...?
>
> Best regards,
> Ellen
IDL> b=[205b,204b,204b,204b,204b,204b,49b,64b]
IDL> print, fix(b, 0, 1, type=5)
17.800000
regards,
Lajos
|
|
|
Re: 8 byte to double? [message #92601 is a reply to message #92600] |
Wed, 20 January 2016 05:34   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
fawltylanguage@gmail.com writes:
>
> On Wednesday, January 20, 2016 at 1:39:07 PM UTC+1, LNpellen wrote:
>> I'm lost - and I thought I had solved this previously, but I simply can't find it (maybe it was in php or something...).
>>
>> Some values in the DICOM header for some vendors happens to save floating (double-presition?) values as 8-bytearrays
>>
>> Is there a simple way in IDL to convert this bytearray to a double without coding the type conversion yourself?
>>
>> I couldn't manage to use the DOUBLE function for this.
>>
>> Ex.:
>> I have the byte array [205 204 204 204 204 204 49 64] and it think from my annoyingly short notes that it should be 17.8...?
>>
>> Best regards,
>> Ellen
>
> IDL> b=[205b,204b,204b,204b,204b,204b,49b,64b]
> IDL> print, fix(b, 0, 1, type=5)
> 17.800000
Lajos is right, but here is a little fuller explanation:
http://www.idlcoyote.com/code_tips/packfloat.php
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
|