Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
reading/writing binary data
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-11-21 (13:15)
From: Olivier Andrieu <oandrieu@n...>
Subject: Re: [Caml-list] reading/writing binary data
> 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 !