caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] reading/converting little endian
@ 2002-02-19  0:54 Attila Kondacs
  0 siblings, 0 replies; 3+ messages in thread
From: Attila Kondacs @ 2002-02-19  0:54 UTC (permalink / raw)
  To: caml-list

I wonder if there is a way to read or convert little endian numbers
in ocaml. I am trying to write an interface to WAV audio files, and their
headers contain vital little endian numbers (as well as some
big endian characters)...

thanks
Attila Kondacs
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] reading/converting little endian
  2002-02-19 15:36 Attila Kondacs
@ 2002-02-22 15:54 ` Xavier Leroy
  0 siblings, 0 replies; 3+ messages in thread
From: Xavier Leroy @ 2002-02-22 15:54 UTC (permalink / raw)
  To: Attila Kondacs; +Cc: caml-list

> I wonder if there is a way to read or convert little endian numbers
> in ocaml. I am trying to write an interface to WAV audio files, and their
> headers contain little endian as well as some
> big endian words...

Your best bet is to read byte per byte and reassemble words yourself:

let input_int2_le ic =
  let b1 = input_byte ic in
  let b2 = input_byte ic in
  b1 lor (b2 lsl 8)

let input_int2_be ic =
  let b1 = input_byte ic in
  let b2 = input_byte ic in
  (b1 lsl 8) lor b2

and similarly for 4-byte integers.

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Caml-list] reading/converting little endian
@ 2002-02-19 15:36 Attila Kondacs
  2002-02-22 15:54 ` Xavier Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Attila Kondacs @ 2002-02-19 15:36 UTC (permalink / raw)
  To: caml-list

I wonder if there is a way to read or convert little endian numbers
in ocaml. I am trying to write an interface to WAV audio files, and their
headers contain little endian as well as some
big endian words...

thanks
Attila Kondacs



-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-02-23 18:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-19  0:54 [Caml-list] reading/converting little endian Attila Kondacs
2002-02-19 15:36 Attila Kondacs
2002-02-22 15:54 ` Xavier Leroy

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).