From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=HTML_MESSAGE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 37206BC68 for ; Mon, 16 Oct 2006 22:32:05 +0200 (CEST) Received: from web27005.mail.ukl.yahoo.com (web27005.mail.ukl.yahoo.com [217.146.177.5]) by concorde.inria.fr (8.13.6/8.13.6) with SMTP id k9GKW4qL031550 for ; Mon, 16 Oct 2006 22:32:04 +0200 Received: (qmail 13964 invoked by uid 60001); 16 Oct 2006 20:32:04 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.fr; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type; b=V66QAPt7/XKpMOUsl0kUK0PUKwl+wEwsNWmNITvrzAchFn0p0kDJxZoD+RsAJONG8hIze5svG1YZtZoClm2R2KZqE3Ki2Jkg+ouVm7KBavBBtRYv3M7UP8OgG7XUmv3DpxX5yxJScKpxCouEcgfQulNThQgWVa/UeVHKXj9nZtI= ; Message-ID: <20061016203204.13962.qmail@web27005.mail.ukl.yahoo.com> Received: from [82.245.142.171] by web27005.mail.ukl.yahoo.com via HTTP; Mon, 16 Oct 2006 20:32:04 GMT Date: Mon, 16 Oct 2006 20:32:04 +0000 (GMT) From: Matthieu Wipliez Subject: Re : [Caml-list] Re: Reading 16 bit floats from stream? To: caml-list MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-26786376-1161030724=:13799" X-j-chkmail-Score: MSGID : 4533EC44.001 on concorde : j-chkmail score : XXX : 5/20 1 X-Miltered: at concorde with ID 4533EC44.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; matthieu:01 byte:01 byte:01 logor:01 logor:01 matthieu:01 gerd:01 stolpmann:01 binary:01 beginner's:01 ocaml:01 bug:01 gerd:01 stolpmann:01 binary:01 --0-26786376-1161030724=:13799 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hello,=0A=0Awhat about converting each byte (represented by an int) to an i= nt32, and then converting those using shifts and logical ors :=0A=0A"in" be= ing our in_channel:=0Alet b0 =3D Int32.of_int (input_byte in)=0Alet b1 =3D = Int32.of_int (input_byte in)=0Alet b2 =3D Int32.of_int (input_byte in)=0Ale= t b3 =3D Int32.of_int (input_byte in)=0A=0Alet res =3D Int32.logor (Int32.l= ogor (Int32.shift_left b0 24) (Int32.shift_left b1 16)) (Int32.logor (Int32= .shift_left b2 8) (Int32.shift_left b3 0)).=0A=0A=0AHope this helps,=0A=0AM= atthieu=0A=0A----- Message d'origine ----=0ADe : Maurizio Colucci =0ACc : caml-list =0AEnvoy=E9 = le : Lundi, 16 Octobre 2006, 19h06mn 46s=0AObjet : Re: [Caml-list] Re: Read= ing 16 bit floats from stream?=0A=0A=0A=0AOn 10/16/06, Gerd Stolpmann wrote:=0AAm Montag, den 16.10.2006, 18:03 +0200 schrieb= Maurizio Colucci:=0A>=0A>=0A> On 10/16/06, Maurizio Colucci wrote:=0A> Hi,=0A=0A>=0A> I need to read a s= equence of single precision floats (16 bits)=0A> from a binary file= . How can I do that?=0A>=0A> Sorry, I mean 32 bits. Single precision floats= are 32 bits.=0A=0A=0AWell, have heard of even 8 bit floats...=0A=0A32 bit = floats can be read. First read the 4 bytes =0AI assume you mean four read_b= ytes calls...=0A=0A=0A=0Aand make an int32 of=0Athem. =0AHow do I create an= int32 with four bytes? =0A=0A=0A=0AThen simply call Int32.float_of_bits.= =0AI get this last one, but I can't imagine the previous step.=0A=0AThanks= =0A=0AMaurizio=0A=0A=0A=0A=0A______________________________________________= _=0ACaml-list mailing list. Subscription management:=0Ahttp://yquem.inria.f= r/cgi-bin/mailman/listinfo/caml-list=0AArchives: http://caml.inria.fr=0ABeg= inner's list: http://groups.yahoo.com/group/ocaml_beginners=0ABug reports: = http://caml.inria.fr/bin/caml-bugs=0A=0A=0A=0A=0A=0A=0A=0A=09=0A=0A=09=0A= =09=09=0A__________________________________________________________________= _________ =0AD=E9couvrez une nouvelle fa=E7on d'obtenir des r=E9ponses =E0 = toutes vos questions ! =0ADemandez =E0 ceux qui savent sur Yahoo! Questions= /R=E9ponses=0Ahttp://fr.answers.yahoo.com --0-26786376-1161030724=:13799 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
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 =3D Int32.of_int (input_byte in)let b1 =3D Int32.of_int (input_byte in)
let b2 =3D Int32.of_int (input= _byte in)
let b3 =3D Int32.of_int (input_byte in)

let res =3D Int= 32.logor (Int32.logor (Int32.shift_left b0 24) (Int32.shift_left b1 16)) (I= nt32.logor (Int32.shift_left b2 8) (Int32.shift_left b3 0)).


Hop= e this helps,

Matthieu

----- Message d'origine ----De : Maurizio Colucci <maurizio.colucci@gmail.com>
Cc : caml-lis= t <caml-list@yquem.inria.fr>
Envoy=E9 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:
=0AAm Montag, den 16.10.2006, 18:03 +0200 schrieb Maurizio Colucci:
&= gt;
>
> On 10/16/06, Maurizio Colucci <
maurizio.colucc= i@gmail.com> wrote:
>       = ;  Hi,=0A
>
>       &nb= sp; I need to read a sequence of single precision floats (16 bits)
>&= nbsp;        from a binary file. How can= I do that?
>
> Sorry, I mean 32 bits. Single precision floats = are 32 bits.
=0A
Well, have heard of even 8 bit floats...

32 b= it floats can be read. First read the 4 bytes

I assum= e you mean four read_bytes calls...

=0Aand make an int32 of
them.

How do I create an int32 with four bytes?

=0AThen simply call Int3= 2.float_of_bits.

I get this last one, but I can't imag= ine the previous step.

Thanks

Maurizio

=0A=
_______________________________________________
Caml-list mailing l= ist. Subscription management:
http://yquem.inria.fr/cgi-bin/= mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://g= roups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/ca= ml-bugs


=0A=09=09
=0AD= =E9couvrez une nouvelle fa=E7on d'obtenir des r=E9ponses =E0 toutes vos que= stions ! =0ADemandez =E0 ceux qui savent sur Yahoo! Questions/R=E9ponses. --0-26786376-1161030724=:13799--