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=2.3 required=5.0 tests=HTML_10_20,HTML_MESSAGE, SPF_NEUTRAL 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 79AE3BC0B for ; Tue, 21 Nov 2006 12:34:54 +0100 (CET) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.234]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id kALBYrpF003601 for ; Tue, 21 Nov 2006 12:34:54 +0100 Received: by wx-out-0506.google.com with SMTP id i29so2208833wxd for ; Tue, 21 Nov 2006 03:34:53 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=PNn3r40PsJo2g/32pASp39a+yUquppa06WNaiCRqg6euDBypbOKQh1nvsoLFzB5hosLHqnU/P0qtoHzdyuc+igBun43uN+HaKdgXjuCaD9Wgw4W/BU2R/pBGdP5YAJa5lw60+NJJlz4VfS92oPTdUGd5tCUNky0CQQwp5x9n5RI= Received: by 10.90.29.2 with SMTP id c2mr5019444agc.1164108892946; Tue, 21 Nov 2006 03:34:52 -0800 (PST) Received: by 10.35.113.4 with HTTP; Tue, 21 Nov 2006 03:34:52 -0800 (PST) Message-ID: <6aeedf580611210334p41d2ba00jcceb00da3af0e3d2@mail.gmail.com> Date: Tue, 21 Nov 2006 11:34:52 +0000 From: "=?ISO-8859-1?Q?D=E1rio_Abdulrehman?=" To: caml-list@yquem.inria.fr Subject: reading/writing binary data MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_15879_20525159.1164108892865" X-j-chkmail-Score: MSGID : 4562E45D.000 on discorde : j-chkmail score : X : 0/20 1 X-Miltered: at discorde with ID 4562E45D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; encodes:01 ocaml:01 bigarray:01 ocaml:01 decoding:01 bigarray:01 encodes:01 decoding:01 rio:98 unix:01 unix:01 wrote:01 wrote:01 ideally:01 ideally:01 ------=_Part_15879_20525159.1164108892865 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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. 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? I need to read the data fast without having to manipulate bits beyond the minimum decoding to get my data back from the binary representation. Thanks. let test_data = open_out_bin "test.data" in output_binary_int test_data 1 let data = let fd = Unix.openfile "test.data" [Unix.O_RDONLY] 0 in Bigarray.Array1.map_file fd Bigarray.int Bigarray.c_layout false (-1) ------=_Part_15879_20525159.1164108892865 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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.

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?

I need to read the data fast without having to manipulate bits beyond the minimum decoding to get my data back from the binary representation.

Thanks.

let test_data = open_out_bin "test.data" in
  output_binary_int test_data 1

let data =
  let fd = Unix.openfile "test.data" [Unix.O_RDONLY] 0 in
  Bigarray.Array1.map_file fd Bigarray.int Bigarray.c_layout false (-1)


------=_Part_15879_20525159.1164108892865--