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

Home » Public Forums » archive » Re: Converting Byte Arrays
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: Converting Byte Arrays [message #10046 is a reply to message #10032] Mon, 06 October 1997 00:00 Go to previous messageGo to previous message
David Foster is currently offline  David Foster
Messages: 341
Registered: January 1996
Senior Member
Thomas Price wrote:
>
> I am struggling with a file i/o problem. I have a data file which comes
> from a PC. I know the data structure in terms of how many bytes correspond
> to each entry in the file and what file type for each of these entries
> (i.e. integer, real, etc). Generally, I two bytes into a variable for a
> integer and 4 bytes for a real. I can convert the integers simply enough.
> For a variable named id which is a bytarr(2) the integer is simply
> 256*id(1)+id(0). However, how can I convert the 4 byte arrays which are
> floats into the proper numbers? I seem to come up with gibberish if I do a
> simple float(val) where val=byytarr(4).
>
> Any thoughts or tricks? All help much appreciated.

Remember that the byte-ordering on Suns and PCs is reversed. I think
the easiest and most efficient thing to do would be to read the
data into variables directly, using the appropriate data-type,
and then convert them using the BYTEORDER() routine.

If you are going to convert short integers by hand then I think
you might need:

256*id[0]+id[1]

to account for the reversed byte ordering.

Dave
--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: parser ?
Next Topic: Re: typesetting math in IDL plots

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

Current Time: Mon Dec 01 09:33:39 PST 2025

Total time taken to generate the page: 1.04391 seconds