help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bit shift oddity?


From: Douglas Lewan
Subject: Re: Bit shift oddity?
Date: Mon, 19 Oct 2020 11:19:20 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

Nice. Thank you.

On 10/19/20 5:23 AM, Gregory Heytings wrote:


I see the following:

  ELISP> (= (lsh -1 (lognot 0)) (lsh -2 (lognot 0)))

  t

  ELISP> (= (lsh -1 (lognot 0)) (lsh -3 (lognot 0)))

  nil

The first seems odd to me. Is it really what's expected?


Yes, it's what is expected.  The docstring of lsh says:

"(lsh VALUE COUNT) ... If COUNT is negative, shifting is actually to the right. In this case, if VALUE is a negative fixnum treat it as unsigned ..."

-1 (decimal) = 111...111 (binary)
-2 (decimal) = 111...110 (binary)

If you shift these two numbers to the right, you get the exact same result: 011...111, that is, `most-positive-fixnum'.

--
,Doug
d.lewan2000@gmail.com
(908) 720 7908

You know, it's amazing how much closer to 0 that 8 067 332 is than 15 is. (2020 
Oct 18)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]