Version française
Home     About     Download     Resources     Contact us    
Browse thread
reading/writing binary data
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Florian Hars <hars@b...>
Subject: Re: [Caml-list] reading/writing binary data
Jon Harrop schrieb:
> I want to see those HOFs:
> 
>   let output_binary_int_little_endian ch n =
>     List.iter (fun i -> output_byte ch ((n lsr i) land 0xff)) [0; 8; 16; 24];;

Why not go the whole way?

let little_endian = [0; 8; 16; 24]
let middle_endian = [16; 24; 0; 8]
let big_endian = [24; 16; 8; 0]

let output_binary_int endianness ch n =
   List.iter (fun i -> output_byte ch ((n lsr i) land 0xff)) endianness

Now all we need is a PDP-11 port...

Yours, Florian.