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 16 bit floats from stream?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-10-16 (23:31)
From: Jacques Garrigue <garrigue@m...>
Subject: Re: [Caml-list] Re: Reading 16 bit floats from stream?
From: Tom <>

> val Pervasives.input_binary_int : in_channel -> int

This will indeed read a 32-bit integer, but on a 32-bit architecture
ocaml int's are 31-bit, so you loose the highest bit.
Note that on a 64-bit architecture this is sufficient for 32-bit

> val Pervasives.read_int : unit -> int

This one reads a string...

> val Marshal.from_channel : in_channel -> 'a

And this one reads a marshalled value, which must include a special
header indicating its ocaml representation.

So if you really need to read a full 32-bit integer, none of these
will work, and you must do the job by hand.

Jacques Garrigue