caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re : [Caml-list] Re: Reading 16 bit floats from stream?
@ 2006-10-16 20:32 Matthieu Wipliez
  0 siblings, 0 replies; only message in thread
From: Matthieu Wipliez @ 2006-10-16 20:32 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 2097 bytes --]

Hello,

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,

Matthieu

----- Message d'origine ----
De : Maurizio Colucci <maurizio.colucci@gmail.com>
Cc : caml-list <caml-list@yquem.inria.fr>
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 <info@gerd-stolpmann.de> wrote:
Am Montag, den 16.10.2006, 18:03 +0200 schrieb Maurizio Colucci:
>
>
> On 10/16/06, Maurizio Colucci <maurizio.colucci@gmail.com> 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
them. 
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.

Thanks

Maurizio




_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs







	

	
		
___________________________________________________________________________ 
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Demandez à ceux qui savent sur Yahoo! Questions/Réponses
http://fr.answers.yahoo.com

[-- Attachment #2: Type: text/html, Size: 3672 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-10-16 20:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-16 20:32 Re : [Caml-list] Re: Reading 16 bit floats from stream? Matthieu Wipliez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).