Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] A grave bug in logical shift right op?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jed Davis <jdev@p...>
Subject: [Caml-list] Re: A grave bug in logical shift right op?
Eray Ozkural <exa@kablonet.com.tr> writes:

> I'm using the debian package in testing....
>
> orion:fealn-attack$ ledit ocaml
>         Objective Caml version 3.07+2
>
> # Printf.printf "%X" 0xffffffff;;
> 7FFFFFFF- : unit = ()
> # Printf.printf "%lx" (Int32.of_int 0xffffffff);;
> ffffffff- : unit = ()
> # -1 lsr 24;;
> - : int = 127
> # Int32.shift_right_logical (Int32.of_int (-1)) 24;;
> - : int32 = 255l
>
> What's going on here? Something's eating the most significant bit in
> both hexadecimal output routine and the logical shift right
> operator. Somebody please help me! My cipher isn't working!!!

The size of an int is one bit less than the machine's word size, so 31
bits on a 32-bit arch; this is because the internal representation of
an OCaml value uses the LSB to distinguish between an int (stored in
the top n-1 bits) and some other kind of object.


-- 
Jed Davis <jldavis@cs.oberlin.edu>  Selling of self: http://panix.com/~jdev/rs/
<jdev@panix.com>  PGP<-finger A098:903E:9B9A:DEF4:168F:AA09:BF07:807E:F336:59F9
\   "But life wasn't yes-no, on-off.  Life was shades of gray, and rainbows
/\   not in the order of the spectrum."  -- L. E. Modesitt, Jr., _Adiamante_

-------------------
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