[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to read two-bytes variables from a file saved in Mac?




"Xiong Hu" <xhu@conrad.ece.uiuc.edu> writes:

> Hi! Does somebody know how to read the two-bytes variables from a file saved
> in Macintosh?
> 
> I am trying reading the image data in PC platform. The image data saved in
> IPlab in Mac. And I found out the difference of the way the data be saved in
> between PC and Mac. For example, a two- bytes integer will be saved like:
> 0[low byte]1[high byte] in PC platform. But in Mac, it will be saved like:
> 1[high byte]0[low byte].
> 
> So in PC when I try to read a file saved in Mac, I need to read byte by byte
> and do transform in the right way to get the right value of each pixel. But
> I think it is not a good way. I wonder if there are any "keywords" or
> "command" can help me solve this problem directly and efficiently.

You are dealing with an issue called "endianness," which refers to how
a particular CPU stores multi-byte values.

You should investigate the SWAP_* keywords to OPEN, one of them should
be able to help you.  If you need to selectively swap data (ie some
values are byte-swapped and others are not), then you can investigate
the BYTEORDER function, which is used after reading the data.

Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------