Date: Mon, 4 Feb 2008 13:20:14 +0100 From: "Heiko Wundram (Beenic)" <wundram@beenic.net> To: freebsd-questions@freebsd.org Subject: Re: Endianness of freeBSD Message-ID: <200802041320.14955.wundram@beenic.net> In-Reply-To: <1563a4fd0802040403x2b71eaa1yd3d8f78e7742843b@mail.gmail.com> References: <1563a4fd0802040403x2b71eaa1yd3d8f78e7742843b@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 following: unsigned long test = 0x12345678; char* ptest = (char*)&test; if( *ptest == 0x78 ) <is little> else if( *ptest == 0x12 ) <is big> else <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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200802041320.14955.wundram>