From owner-freebsd-questions@FreeBSD.ORG Mon Feb 4 12:18:52 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 86F5516A417 for ; Mon, 4 Feb 2008 12:18:52 +0000 (UTC) (envelope-from wundram@beenic.net) Received: from mail.beenic.net (mail.beenic.net [83.246.72.40]) by mx1.freebsd.org (Postfix) with ESMTP id 47CDB13C502 for ; Mon, 4 Feb 2008 12:18:52 +0000 (UTC) (envelope-from wundram@beenic.net) Received: from [192.168.1.32] (a89-182-21-0.net-htp.de [89.182.21.0]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.beenic.net (Postfix) with ESMTP id 2A360A44538 for ; Mon, 4 Feb 2008 13:18:51 +0100 (CET) From: "Heiko Wundram (Beenic)" Organization: Beenic Networks GmbH To: freebsd-questions@freebsd.org Date: Mon, 4 Feb 2008 13:20:14 +0100 User-Agent: KMail/1.9.7 References: <1563a4fd0802040403x2b71eaa1yd3d8f78e7742843b@mail.gmail.com> In-Reply-To: <1563a4fd0802040403x2b71eaa1yd3d8f78e7742843b@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200802041320.14955.wundram@beenic.net> Subject: Re: Endianness of freeBSD X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Feb 2008 12:18:52 -0000 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 ) else if( *ptest == 0x12 ) 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