From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 10A48BC0B for ; Tue, 21 Nov 2006 14:15:19 +0100 (CET) Received: from kraid.nerim.net (smtp-102-tuesday.nerim.net [62.4.16.102]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id kALDFI34022069 for ; Tue, 21 Nov 2006 14:15:18 +0100 Received: from webmail.nerim.net (archimonde.nerim.net [62.4.16.97]) by kraid.nerim.net (Postfix) with ESMTP id BD19D415F3; Tue, 21 Nov 2006 14:15:17 +0100 (CET) Received: from 213.30.139.86 (SquirrelMail authenticated user oandrieu) by webmail.nerim.net with HTTP; Tue, 21 Nov 2006 14:15:14 +0100 (CET) Message-ID: <32511.213.30.139.86.1164114914.squirrel@webmail.nerim.net> In-Reply-To: <6aeedf580611210334p41d2ba00jcceb00da3af0e3d2@mail.gmail.com> References: <6aeedf580611210334p41d2ba00jcceb00da3af0e3d2@mail.gmail.com> Date: Tue, 21 Nov 2006 14:15:14 +0100 (CET) Subject: Re: [Caml-list] reading/writing binary data From: "Olivier Andrieu" To: =?iso-8859-1?Q?D=E1rio_Abdulrehman?= Cc: caml-list@inria.fr User-Agent: SquirrelMail/1.4.5 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Miltered: at discorde with ID 4562FBE6.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; andrieu:01 oandrieu:01 encodes:01 ocaml:01 bigarray:01 ocaml:01 int':01 big-endian:01 bigarray:01 wrote:01 ideally:01 caml-list:01 ints:01 ints:01 binary:01 > I am writing a program that encodes data in 32 bit ints. Ideally I would > like to have 32 bit unsigned ints, but OCaml only has 31 bit signed ints. It also has 32 bits signed ints (and 64 bits). > I have a large binary file with the data that I will mmap with the > Bigarray.Array1.map_file function. > > When I test the following code I am puzzled by the fact that Ocaml doesn't > give me back the int in the same format as I wrote it. > > Why doesn't OCaml read back data in the same format? because `output_binary_int' uses a big-endian encoding (cf. the reference manual) whereas Bigarray.map_file uses the native endianess (probably little-endian in your case). Don't use different methods to write your data and read it back ! -- Olivier