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 SAA12828; Mon, 26 Jul 2004 18:46:50 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA13404 for ; Mon, 26 Jul 2004 18:46:49 +0200 (MET DST) Received: from yquem.inria.fr (yquem.inria.fr [128.93.8.37]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i6QGkmEV023550 for ; Mon, 26 Jul 2004 18:46:48 +0200 Received: by yquem.inria.fr (Postfix, from userid 18180) id 6EAACBC78; Mon, 26 Jul 2004 18:46:48 +0200 (CEST) Date: Mon, 26 Jul 2004 18:46:48 +0200 From: Xavier Leroy To: caml-list@inria.fr Subject: Re: [Caml-list] 32-bit unsigned integers Message-ID: <20040726164648.GB6618@yquem.inria.fr> References: <20040726153809.GA14309@galois> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040726153809.GA14309@galois> User-Agent: Mutt/1.3.28i X-Miltered: at nez-perce with ID 41053578.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 -bits:01 modulus:01 -bits:01 vice-versa:01 struct:01 printf:01 sprintf:01 modulus:01 -bit:01 caml:01 int:01 int:01 arithmetic:01 mul:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Does a type representing unsigned 32-bits integer exist in Caml ? Yes: it's called int32. Think about it: being "unsigned" or "signed" is not a property of the representation (it will be 32 binary digits in both cases), it's just that some operations (division, modulus and comparisons) interpret those bits differently. > All I'd need is an abstract type defining these integers, plus some > functions to go from strings to 32-bits unsigned integers and vice-versa. Here you are: module UInt32 = struct type t = int32 let of_string = Int32.of_string let to_string n = Printf.sprintf "%lu" n end You can throw in some arithmetic operations as well: let add = Int32.add let sub = Int32.sub let mul = Int32.mul etc. As I said above, the only operations that need to be treated specially are comparisons and division/modulus. Hope this helps, - 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