From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA10010; Fri, 4 May 2001 11:37:31 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA10040 for ; Fri, 4 May 2001 11:37:30 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f449bQD17233; Fri, 4 May 2001 11:37:26 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA10013; Fri, 4 May 2001 11:37:27 +0200 (MET DST) Date: Fri, 4 May 2001 11:37:27 +0200 From: Xavier Leroy To: Miles Egan Cc: caml-list@inria.fr Subject: Re: [Caml-list] printable digest strings Message-ID: <20010504113727.A9728@pauillac.inria.fr> References: <20010503153234.A28259@caddr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20010503153234.A28259@caddr.com>; from miles@caddr.com on Thu, May 03, 2001 at 03:32:34PM -0700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I can't seem to find a function to create printable versions of the > digest strings generated by the digest module, like the output of > the common unix md5sum utility. Am I missing something or does it > not exist? It does not exist, but as you said it could be handy. > If not, it might be a handy addition to the Digest > module. At the moment I'm using this fairly gross code of my own: You can use Printf.sprintf "%02x" to convert each byte to hexadecimal in a more concise way. E.g.: let string_map f s = let rec map_aux res idx = if idx < 0 then res else map_aux (f s.[idx] :: res) (idx - 1) in map_aux [] (String.length s - 1) let hexstring s = String.concat "" (string_map (fun c -> Printf.sprintf "%02x" (Char.code c)) s) Or in a more imperative style (real programmers don't build intermediate lists :-) let hexstring s = let res = String.create (String.length s * 2) in for i = 0 to String.length s - 1 do String.blit (Printf.sprintf "%02x" (Char.code s.[i])) 0 res (2 * i) 2 done; res Hope this helps, - Xavier Leroy ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr