From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 506ADBCAF for ; Thu, 16 Jun 2005 21:32:21 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j5GJWK0T026870 for ; Thu, 16 Jun 2005 21:32:20 +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 VAA17508 for ; Thu, 16 Jun 2005 21:32:20 +0200 (MET DST) Received: from smtp6.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.25]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j5GJWK2D006920 for ; Thu, 16 Jun 2005 21:32:20 +0200 Received: from me-wanadoo.net (unknown [127.0.0.1]) by mwinf0603.wanadoo.fr (SMTP Server) with ESMTP id E2EE61C001F1 for ; Thu, 16 Jun 2005 21:32:19 +0200 (CEST) Received: from morgana (ARennes-257-1-27-174.w81-53.abo.wanadoo.fr [81.53.10.174]) by mwinf0603.wanadoo.fr (SMTP Server) with ESMTP id B1EAF1C0024A; Thu, 16 Jun 2005 21:32:19 +0200 (CEST) X-ME-UUID: 20050616193219728.B1EAF1C0024A@mwinf0603.wanadoo.fr Received: from david by morgana with local (Exim 4.50) id 1Dj066-0001BT-95; Thu, 16 Jun 2005 21:32:18 +0200 To: Nicolas George Cc: Caml mailing list Subject: Re: [Caml-list] How to handle endianness and binary string conversion for 32 bits integers (Int32)? References: <87slzima67.fsf@linux-france.org> <20050616190206.GA553@clipper.ens.fr> From: David MENTRE Organization: none Date: Thu, 16 Jun 2005 21:32:18 +0200 In-Reply-To: <20050616190206.GA553@clipper.ens.fr> (Nicolas George's message of "Thu, 16 Jun 2005 21:02:07 +0200") Message-ID: <87aclqm725.fsf@linux-france.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Miltered: at concorde with ID 42B1D3C4.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42B1D3C4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 binary:01 integers:01 endian:01 integers:01 externally:01 byte:01 byte:01 writes:01 int:01 data:02 nicolas:02 nicolas:02 ens:02 chapter:02 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: Hello Nicolas, Nicolas George writes: >> 1. convert between big and little endian 32 bits integers; > > Don't do that. Except that I'm writing a network interface that should be specified so that externally written programs can read my data. 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. So I'll follow that approach, which is close to yours and is independent of machine endianness. Thank you for the tip, ;-) Yours, d. -- pub 1024D/A3AD7A2A 2004-10-03 David MENTRE 5996 CC46 4612 9CA4 3562 D7AC 6C67 9E96 A3AD 7A2A