caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Matthieu Wipliez <mwipliez@yahoo.fr>
To: caml-list <caml-list@yquem.inria.fr>
Subject: Re : [Caml-list] Re: Reading 16 bit floats from stream?
Date: Mon, 16 Oct 2006 20:32:04 +0000 (GMT)	[thread overview]
Message-ID: <20061016203204.13962.qmail@web27005.mail.ukl.yahoo.com> (raw)

[-- 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 --]

                 reply	other threads:[~2006-10-16 20:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061016203204.13962.qmail@web27005.mail.ukl.yahoo.com \
    --to=mwipliez@yahoo.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).