Re: Way to determine big/little endian? [message #26648] |
Thu, 20 September 2001 06:38 |
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  |
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  |
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
------------------------------------------------------------ --------------
|
|
|
|