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 OAA29768; Wed, 2 Apr 2003 14:24: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 OAA30225 for ; Wed, 2 Apr 2003 14:24:48 +0200 (MET DST) Received: from lri.lri.fr (lri.lri.fr [129.175.15.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h32COl914333 for ; Wed, 2 Apr 2003 14:24:47 +0200 (MET DST) Received: from serveur-mail.lri.fr (serveur-mail [129.175.8.90]) by lri.lri.fr (8.11.6p2/jtpda-5.3.2) with ESMTP id h32Bi7A14449 ; Wed, 2 Apr 2003 13:44:07 +0200 (MEST) Received: from serveur-demons (mail@serveur-demons [129.175.8.130]) by serveur-mail.lri.fr (8.11.6/jtpda-5.3.2) with ESMTP id h32Bi1x19273 ; Wed, 2 Apr 2003 13:44:02 +0200 (MEST) Received: from marche by serveur-demons with local (Exim 3.35 #1 (Debian)) id 190gev-0008OB-00; Wed, 02 Apr 2003 13:44:01 +0200 From: Claude Marche MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <16010.52481.412613.884297@mailhost.lri.fr> Date: Wed, 2 Apr 2003 13:44:01 +0200 To: Brian Hurt Cc: Ocaml Mailing List Subject: Re: [Caml-list] Bug? Printf, %X and negative numbers In-Reply-To: References: X-Mailer: VM 7.03 under Emacs 20.7.2 X-MailScanner: Found to be clean X-Spam: no; 0.00; lri:01 caml-list:01 bug:01 printf:01 qlogic:01 3.06:01 paris-sud:01 phoneto:01 91405:01 orsay:01 faxto:01 ocaml:01 caml:01 writes:01 thread:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >>>>> "Brian" == Brian Hurt writes: Brian> $ ocaml Brian> Objective Caml version 3.06 Brian> # Printf.printf "%08X\n" (1 lsl 30);; Brian> C0000000 Brian> - : unit = () Brian> # Printf.printf "%010X\n" (1 lsl 30);; Brian> 00C0000000 Brian> - : unit = () Brian> # Brian> I expected output of 40000000, not C0000000. Note that this isn't a case Brian> of simple sign extension, as the second example demonstrates. Where'd the Brian> extra bit come from? Sorry to come back at the very beginning of this thread, but I'd like to add my two centeuros: I feel that the first answer is correct, but the second is wrong. Why? (1 lsl 30) is -2^30, right ? and the format "%nX" means the hexadecimal 2-complement representation of the argument, on n hexdigits, right ? So I think Printf.printf "%08X\n" (1 lsl 30);; should write C0000000 and Printf.printf "%010X\n" (1 lsl 30);; should write FFC0000000. -- | Claude Marché | mailto:Claude.Marche@lri.fr | | LRI - Bât. 490 | http://www.lri.fr/~marche/ | | Université de Paris-Sud | phoneto: +33 1 69 15 64 85 | | F-91405 ORSAY Cedex | faxto: +33 1 69 15 65 86 | ------------------- 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