Re: Endian-ness [message #29233] |
Fri, 08 February 2002 13:18  |
Liam E. Gumley
Messages: 378 Registered: January 2000
|
Senior Member |
|
|
Jonathan Joseph wrote:
> 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).
;---
FUNCTION BIG_ENDIAN
;- Returns true (1B) if the host platform is big endian
;- (most significant byte first)
return, 1B - byte(1L, 0L)
END
;---
FUNCTION LITTLE_ENDIAN
;- Returns true (1B) if the host platform is little endian
;- (least significant byte first)
return, byte(1L, 0L)
END
;---
IDL Version 5.3 (IRIX mipseb). (c) 1999, Research Systems, Inc.
IDL> print, big_endian(), little_endian()
1 0
IDL Version 5.3 (Win32 x86). (c) 1999, Research Systems, Inc.
IDL> print, big_endian(), little_endian()
0 1
Cheers,
Liam.
Practical IDL Programming
http://www.gumley.com/
|
|
|