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

Home » Public Forums » archive » Re: Endian-ness
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: Endian-ness [message #29234 is a reply to message #29233] Fri, 08 February 2002 13:14 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jonathan Joseph (jj21@cornell.edu) writes:

> Is there a system variable that gives the endian-ness of the current
> hardware? I am reading a file which tells me the endian-ness of the
> data, and I'd like to swap_endian if it is different from the current
> hardware. In lieu of finding a system variable to compare to, I have
> done this:
>
> test_int = 1
> byteorder,test_int,/ntohs
> big_endian = test_int eq 1
>
> "network" byte order is big-endian, so I convert a 1 to the host
> byte-order and see if it's still a 1.
>
> This way works fine, but it seems as thought I'm missing something.
> Is there a better way? Using the byteorder routine to convert the data
> is not an option (unless it's been improved for 5.5).

I don't know of a system variable. I've always used this
little function:

FUNCTION IS_LITTLE_ENDIAN
little_endian = (BYTE(1, 0, 1))[0]
IF (little_endian) THEN RETURN, 1 ELSE RETURN, 0
END

IDL> IF Is_Little_Endian() THEN Print, 'This is little endian, bro.'

I've always had success with the SWAP_IF_BIG_ENDIAN and
SWAP_IF_LITTLE_ENDIAN keywords on OPEN statements, however.
I presume these use the BYTEORDER routine, which I have
also never had a moments trouble with. (I live a clean
and wholesome life, though, which may explain it.)

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Chinese characters?
Next Topic: Re: Help! Slow object graphics.

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

Current Time: Wed Oct 08 16:51:58 PDT 2025

Total time taken to generate the page: 0.00370 seconds