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 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Way to determine big/little endian? [message #26648] Thu, 20 September 2001 06:38
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
David Fanning <david@dfanning.com> writes:

> Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:
>
>> 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
>
> Gosh, now I'm *really* embarrassed about my simple little
> contribution. I think I only had two sets of nested
> parentheses. :-(

Round blades! Round blades! :-) Actually I only had two sets of nested
parentheses as well. Sigh, I like your submission a little better.
It captures the essence of the test a little better.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Way to determine big/little endian? [message #26660 is a reply to message #26648] Wed, 19 September 2001 22:02 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Craig Markwardt (craigmnet@cow.physics.wisc.edu) writes:

> 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

Gosh, now I'm *really* embarrassed about my simple little
contribution. I think I only had two sets of nested
parentheses. :-(

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
Re: Way to determine big/little endian? [message #26661 is a reply to message #26660] Wed, 19 September 2001 21:45 Go 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
------------------------------------------------------------ --------------
Re: Way to determine big/little endian? [message #26663 is a reply to message #26661] Wed, 19 September 2001 21:36 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
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

Here is an article on the subject, with a little snippet
of code to tell you where you are.

http://www.dfanning.com/tips/endian_machines.html

The code looks like this:

little_endian = (BYTE(1, 0, 1))[0]
IF (little_endian) THEN $
Print, "I'm little endian." ELSE $
Print, "I'm big endian."

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
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Fri Oct 10 16:31:14 PDT 2025

Total time taken to generate the page: 0.96270 seconds