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 (11:34)
From: Dário_Abdulrehman <drehman31@g...>
Subject: 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.

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.


let test_data = open_out_bin "" in
  output_binary_int test_data 1

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