Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Bug? Printf, %X and negative numbers
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Claude Marche <Claude.Marche@l...>
Subject: Re: [Caml-list] Bug? Printf, %X and negative numbers
>>>>> "Brian" == Brian Hurt <brian.hurt@qlogic.com> 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