Endianness of freeBSD

Heiko Wundram (Beenic) wundram at beenic.net
Mon Feb 4 12:18:52 UTC 2008

Am Montag, 4. Februar 2008 13:03:25 schrieb navneet Upadhyay:
> 1. Is FreeBSD little Endian like windows?

FreeBSD endianness depends on the hardware architecture it runs on (as 
endianness is a hardware characterization). (Very) generally, anything that's 
related to an Intel CPU is little-endian, whereas anything that's related to 
a Motorola, IBM or Sparc CPU is big-endian.

(Modern) Windows exists only on little-endian hardware [Intel, AMD and clones] 
(AFAIK, someone correct me here), so basically it's always little-endian, you 
could say that. There were Windows versions for other CPUs, though, back in 
the Windows NT days, which ran on Alpha workstations which were big-endian.

> 2. Linux is Big endian?

Same as for FreeBSD.

> wrote a code int i = 1;    if((i >> 1) == 0) little else big
> got little on all platforms bsd,linux,windows.

This won't tell you what endianness the platform has. It'll say "little" for 
any architecture (because ( 1 >> 1 ) == 0 for any CPU that knows how to do 
binary shifts).

What you can use to test for little or big-endianness, is something like the 

unsigned long test = 0x12345678;
char* ptest = (char*)&test;

if( *ptest == 0x78 )
	<is little>
else if( *ptest == 0x12 )
	<is big>
	<something else ?>

> *Does endianness depends on OS or the hardware?*

As I said above: it depends on the hardware. There is even hardware (ARM, in 
particular) which can run in little- or big-endian mode, depending on how it 
is initialized.

Heiko Wundram
Product & Application Development

More information about the freebsd-questions mailing list