Re: Accessing bits in a floating point number [message #10424] |
Fri, 21 November 1997 00:00 |
Thomas A. McGlynn
Messages: 23 Registered: March 1996
|
Junior Member |
|
|
Brian Chafin wrote:
>
> I have a somewhat peculiar problem and would like to know if anyone has
> a solution for it.
>
> I am reading a 16-bit floating point number from an HDF file. This
> 16-bit number was originally two 1-byte integers which were stuffed into
> a 16-bit float. This was done in C and don't ask why it was done this
> way.
>
> When the float is read into IDL using the native IDL HDF commands, the
> result is a 32-bit float.
>
> Is there any way to extract the original two 1-byte integers from this
> IDL float?
>
> Thanks,
>
> Brian
>
You can convert the floats to a byte array and then look at the
bytes, e.g.,
myBytes = byte(myFloat,0, 4)
will make myBytes a byte array of dimension 4 with
the constituent bytes of myFloat. So assuming the
HDF routines converted it faithfully you can get the
two bytes back.
Hope this helps,
Tom McGlynn
|
|
|
Re: Accessing bits in a floating point number [message #10427 is a reply to message #10424] |
Fri, 21 November 1997 00:00  |
Kevin Ivory
Messages: 71 Registered: January 1997
|
Member |
|
|
Brian Chafin wrote:
> I am reading a 16-bit floating point number from an HDF file. This
> 16-bit number was originally two 1-byte integers which were stuffed into
> a 16-bit float. This was done in C and don't ask why it was done this
> way.
>
> When the float is read into IDL using the native IDL HDF commands, the
> result is a 32-bit float.
>
> Is there any way to extract the original two 1-byte integers from this
> IDL float?
I have never heard of or used 16 bit floats, but if you want to reverse
the 32 bit float to a 16 bit float it seems you will have to know the
bit positioning of both. I am not familiar with HDF either, but in a
normal binary file I would read of either a 16 bit integer and
do the byte-extracting from that or read the two 8 bit integers straight
out of the file. How about giving the HDF declaration the data type
INT DFNT_INT16 and going on from there?
Best regards
Kevin
--
Kevin Ivory Tel: +49 5556 979 434
Max-Planck-Institut fuer Aeronomie Fax: +49 5556 979 240
Max-Planck-Str. 2 mailto:Kevin.Ivory@linmpi.mpg.de
D-37191 Katlenburg-Lindau, GERMANY http://www.gwdg.de/~kivory2/
|
|
|