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
Re : [Caml-list] Re: 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 (20:32)
From: Matthieu Wipliez <mwipliez@y...>
Subject: Re : [Caml-list] Re: Reading 16 bit floats from stream?

what about converting each byte (represented by an int) to an int32, and then converting those using shifts and logical ors :

"in" being our in_channel:
let b0 = Int32.of_int (input_byte in)
let b1 = Int32.of_int (input_byte in)
let b2 = Int32.of_int (input_byte in)
let b3 = Int32.of_int (input_byte in)

let res = Int32.logor (Int32.logor (Int32.shift_left b0 24) (Int32.shift_left b1 16)) (Int32.logor (Int32.shift_left b2 8) (Int32.shift_left b3 0)).

Hope this helps,


----- Message d'origine ----
De : Maurizio Colucci <>
Cc : caml-list <>
Envoyé le : Lundi, 16 Octobre 2006, 19h06mn 46s
Objet : Re: [Caml-list] Re: Reading 16 bit floats from stream?

On 10/16/06, Gerd Stolpmann <> wrote:
Am Montag, den 16.10.2006, 18:03 +0200 schrieb Maurizio Colucci:
> On 10/16/06, Maurizio Colucci <> wrote:
>         Hi,

>         I need to read a sequence of single precision floats (16 bits)
>         from a binary file. How can I do that?
> Sorry, I mean 32 bits. Single precision floats are 32 bits.

Well, have heard of even 8 bit floats...

32 bit floats can be read. First read the 4 bytes 
I assume you mean four read_bytes calls...

and make an int32 of
How do I create an int32 with four bytes? 

Then simply call Int32.float_of_bits.
I get this last one, but I can't imagine the previous step.



Caml-list mailing list. Subscription management:
Beginner's list:
Bug reports:


Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Demandez à ceux qui savent sur Yahoo! Questions/Réponses