From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 087FDBCAF for ; Thu, 16 Jun 2005 22:14:27 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j5GKEQlk009623 for ; Thu, 16 Jun 2005 22:14:26 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA18382 for ; Thu, 16 Jun 2005 22:14:26 +0200 (MET DST) Received: from nef2.ens.fr (nef2.ens.fr [129.199.96.40]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j5GKEPYX009620 for ; Thu, 16 Jun 2005 22:14:25 +0200 Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef2.ens.fr (8.13.2/1.01.28121999) with ESMTP id j5GKEP3f013625 ; Thu, 16 Jun 2005 22:14:25 +0200 (CEST) X-Envelope-To: caml-list@inria.fr Received: from (george@localhost) by clipper.ens.fr (8.13.1/jb-1.1) Date: Thu, 16 Jun 2005 22:14:25 +0200 From: Nicolas George To: David MENTRE Cc: Caml mailing list Subject: Re: [Caml-list] How to handle endianness and binary string conversion for 32 bits integers (Int32)? Message-ID: <20050616201425.GA25422@clipper.ens.fr> References: <87slzima67.fsf@linux-france.org> <20050616190206.GA553@clipper.ens.fr> <87aclqm725.fsf@linux-france.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="M9NhX3UHpAaciwkO" Content-Disposition: inline In-Reply-To: <87aclqm725.fsf@linux-france.org> User-Agent: Mutt/1.5.9i X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.5.10 (nef2.ens.fr [129.199.96.32]); Thu, 16 Jun 2005 22:14:25 +0200 (CEST) X-Miltered: at nez-perce with ID 42B1DDA2.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42B1DDA1.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 binary:01 integers:01 externally:01 endian:01 sequences:01 integers:01 ocaml:01 alas:01 byte:01 byte:01 int:01 data:02 portability:02 nicolas:02 X-Attachments: type="application/pgp-signature" name="signature.asc" X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: --M9NhX3UHpAaciwkO Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable L'octidi 28 prairial, an CCXIII, David MENTRE a =E9crit=A0: > Except that I'm writing a network interface that should be specified so > that externally written programs can read my data. My point is: you do not need to convert between big and little endian, you only have to convert between sequences of bytes and integers. You never need even to know that integers are stored as bytes in the memory of the computer. In fact, I expect that you could not find access to the internal representation of integers in OCaml, which is a good thing. Most of the portability bugs in C come from people who have not understood the principle of having access to the internal representation of objects (which is not to use it :-). Alas, a lot of books about C are very i86-centered and explain it really badly. > In fact, your post reminded me of a chapter of "The Practice of > Programming" by Kernighan and Pike. They advise to read/write integers > byte by byte using 8 bit masking and shifting. >=20 > So I'll follow that approach, which is close to yours and is independent > of machine endianness. I think this is really exactly the same approach, and I am flattered to have the same position af Kernighan. --M9NhX3UHpAaciwkO Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (SunOS) iD8DBQFCsd2hsGPZlzblTJMRAkBAAJ9fpKgugp/8hslHKcPuTyrqiPqqcQCfXN80 W6w8LgRPGdDMX82ICYJ0m7E= =aPwc -----END PGP SIGNATURE----- --M9NhX3UHpAaciwkO--