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

Home » Public Forums » archive » Re: Accessing bits in a floating point 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: Accessing bits in a floating point number [message #10424] Fri, 21 November 1997 00:00
Thomas A. McGlynn is currently offline  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 Go to previous message
Kevin Ivory is currently offline  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/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: ION (IDL on Net) any remarks to it?
Next Topic: matlab conversion

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

Current Time: Fri Oct 10 01:19:29 PDT 2025

Total time taken to generate the page: 0.95935 seconds