From owner-freebsd-questions@FreeBSD.ORG Fri Mar 4 09:10:37 2011 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 E41B8106564A for ; Fri, 4 Mar 2011 09:10:37 +0000 (UTC) (envelope-from perryh@pluto.rain.com) Received: from agora.rdrop.com (agora.rdrop.com [IPv6:2607:f678:1010::34]) by mx1.freebsd.org (Postfix) with ESMTP id A96E68FC25 for ; Fri, 4 Mar 2011 09:10:37 +0000 (UTC) Received: from agora.rdrop.com (66@localhost [127.0.0.1]) by agora.rdrop.com (8.13.1/8.12.7) with ESMTP id p249Aahj060944 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 4 Mar 2011 01:10:36 -0800 (PST) (envelope-from perryh@pluto.rain.com) Received: (from uucp@localhost) by agora.rdrop.com (8.13.1/8.12.9/Submit) with UUCP id p249AaR2060943; Fri, 4 Mar 2011 01:10:36 -0800 (PST) Received: from fbsd61 by pluto.rain.com (4.1/SMI-4.1-pluto-M2060407) id AA04537; Fri, 4 Mar 11 01:10:03 PST Date: Fri, 04 Mar 2011 01:09:23 -0800 From: perryh@pluto.rain.com To: ertr1013@student.uu.se Message-Id: <4d70ac43.iPJOAUhHtgE0uJR+%perryh@pluto.rain.com> References: <910E776A-D865-4F78-8BE5-E974326636D0@solensky.org> <20110303205010.GA47653@owl.midgard.homeip.net> In-Reply-To: <20110303205010.GA47653@owl.midgard.homeip.net> User-Agent: nail 11.25 7/29/05 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: frank@solensky.org, freebsd-questions@freebsd.org Subject: Re: Bit order == byte order?? 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: Fri, 04 Mar 2011 09:10:38 -0000 Erik Trulsson wrote: > On Thu, Mar 03, 2011 at 11:26:12AM -0500, Frank Solensky wrote: > > In sys/netinet/ip.h, the first octet of the ip header structure > > tests the byte ordering to determine the ordering of the header > > length (ip_hl) and version (ip_v) fields. > > > > My question: that always works? While my reading of the > > language specification document leaves both the ordering of > > the bits within a byte and the bytes within a longer field as > > implementation choices, the two are independent of each other. > > > > I haven't run into a CPU where this assumption was proven > > incorrect ... > > Unless you have a CPU where memory is addressed bit-by-bit rather > than byte-by-byte the ordering of bits within a byte is not only > completely irrelevant, it is also pretty much impossible to > determine programatically. Agreed it is at least difficult to determine programatically, however it is quite important when dealing with hardware that converts between a sequence of bytes and a bitstream, e.g. serial ports, network interfaces, SATA ports. Driver writers had _better_ know which bit of the byte, as well as which byte of a word/longword/quadword, is going on the wire first. The O.P. is absolutely correct that bit order within a byte and byte order within a multibyte field need not, in principle, be the same.