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

Home » Public Forums » archive » Re: Way to determine big/little endian?
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: Way to determine big/little endian? [message #26661 is a reply to message #26660] Wed, 19 September 2001 21:45 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"Mark Rivers" <rivers@cars.uchicago.edu> writes:

> Is there a built-in way to determine if the machine IDL is running on is
> big-endian or little-endian? I would expect that there might be a field in
> !version, but there is not.
>
> Here is what I am doing to set the Boolean value "big_endian":
>
> ; If this is a big-endian machine swap the byte order
> ; I don't know of a built-in IDL test for endianness, do it ourselves
> t1 = 1
> t2 = 1
> byteorder, t2, /sswap, /swap_if_big_endian
> big_endian = (t1 ne t2)
> if (big_endian) then str = swap_endian(str)
>
>
> Is there a simpler way? It would be nice if swap_endian accepted the
> /swap_if_big_endian and /swap_if_little_endian keywords the way byteorder
> now does.

I use this code when I need to. It's pretty much the same as yours,
but I think mine is just a bit cuter :-).

big_endian = (long(['01'xb,'02'xb,'03'xb,'04'xb],0,1))(0) EQ '01020304'xl

I presume you could make your own SWAP_ENDIAN-like function which
computed this value, and then implemented the /SWAP_IF... keywords.

Cheers,
Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: PV-WAVE Device Copy Memory Bug in WinNT
Next Topic: Re: wait loop

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

Current Time: Tue Dec 02 13:57:18 PST 2025

Total time taken to generate the page: 1.60672 seconds