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

Home » Public Forums » archive » Byte to Real conversion
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
Byte to Real conversion [message #14340] Fri, 19 February 1999 00:00 Go to next message
Michael A. Wirth is currently offline  Michael A. Wirth
Messages: 5
Registered: April 1997
Junior Member
Hi,

I am reading some data in from an Magnetic Resonance image which stores
information about the image in
a 14336 byte header. I want to extract some of the data from this header
and am having a problem
with converting data to integers and reals. The integers are 2-bytes and
the reals 4-bytes in length. How does
one convert 4 bytes into a real number?

many thanks,

Michael
Re: Byte to Real conversion [message #14341 is a reply to message #14340] Thu, 18 February 1999 00:00 Go to previous messageGo to next message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Michael A. Wirth (s9601460@131.170.8.11) writes:

> I am reading some data in from an Magnetic Resonance image which stores
> information about the image in
> a 14336 byte header. I want to extract some of the data from this header
> and am having a problem
> with converting data to integers and reals. The integers are 2-bytes and
> the reals 4-bytes in length. How does
> one convert 4 bytes into a real number?

If the variable number is a four-element byte array holding
the floating point number, you convert it back to a float
like this:

real_num = Float(number, 0)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Byte to Real conversion [message #14408 is a reply to message #14340] Tue, 23 February 1999 00:00 Go to previous message
Larry Busse is currently offline  Larry Busse
Messages: 7
Registered: February 1999
Junior Member
Michael A. Wirth wrote:
>
> Hi,
>
> I am reading some data in from an Magnetic Resonance image which stores
> information about the image in
> a 14336 byte header. I want to extract some of the data from this header
> and am having a problem
> with converting data to integers and reals. The integers are 2-bytes and
> the reals 4-bytes in length. How does
> one convert 4 bytes into a real number?
>
> many thanks,
>
> Michael

This is less elegant than structures, but it works...
If you've read the header into a byte array, then you can convert as
follows assuming you know the location (offsets) of the bytes of
interest:

var1 = fix(header,10)
var2 = long(header,12)
var3 = float(header,16)

var1 will be a short integer consisting of the 2 bytes header(10) and
header(11).

var2 will be a long integer consisting of the 4 bytes header(12:15).
var3 will be a float consisting of the 4 bytes header(16:19).

Depending on the archetecture of your machine and the MRI scanner you
might also need to use swap_endian; e.g.,
var3 = swap_endian(float(header,16))
will be needed if you are using a PC version if IDL (Linux or Win) to
analyze data from a GE or Bruker imager.

Good Luck

--
Larry Busse Phone: (606)344-9433
L.J.B. Development Fax: (606)341-8486
3384 Madison Pike mailto:larry@ljbdev.com
Fort Wright, KY 41017 http://www.ljbdev.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Looking for co-occurrence code
Next Topic: Re: PV-WAVE and possibly IDL color maps

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

Current Time: Wed Oct 08 16:01:17 PDT 2025

Total time taken to generate the page: 0.00376 seconds