guile-devel
[Top][All Lists]
Advanced

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

Re: doco on bitwise logicals


From: Kevin Ryde
Subject: Re: doco on bitwise logicals
Date: Sat, 10 May 2003 11:10:39 +1000
User-agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (gnu/linux)

I made this change, but with some tweaks to what I posted for ash:

 - Scheme Procedure: ash n cnt
 - C Function: scm_ash (n, cnt)
     Return N shifted left by CNT bits, or shifted right if CNT is
     negative.  This is an "arithmetic" shift.

     This is effectively a multiplication by 2^CNT, and when CNT is
     negative it's a division, rounded towards negative infinity.
     (Note that this is not the same rounding as `quotient' does.)

     With N viewed as an infinite precision twos complement, `ash'
     means a left shift introducing zero bits, or a right shift
     dropping bits.

          (number->string (ash #b1 3) 2)     => "1000"
          (number->string (ash #b1010 -1) 2) => "101"

          ;; -23 is bits ...11101001, -6 is bits ...111010
          (ash -23 -2) => -6




reply via email to

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