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 
Return to the default flat view Create a new topic Submit Reply
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~
[Message index]
 
Read Message
Read Message
Read Message
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: Fri Oct 10 14:02:14 PDT 2025

Total time taken to generate the page: 1.68120 seconds