guile-devel
[Top][All Lists]
Advanced

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

Re: doco on bitwise logicals


From: Rob Browning
Subject: Re: doco on bitwise logicals
Date: Sun, 04 May 2003 00:35:56 -0500
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.3 (i386-pc-linux-gnu)

Kevin Ryde <address@hidden> writes:

> It occurs to me that integer-length is perhaps not ideal in returning
> 0 for an argument of -1.

I was just trying to figure that (and negative integer-length) out
myself...

> New text for ease of contemplation:

Looks quite good to me.

Two things that I thought of were wondering if we could think of
something other than "highest FOO bit", that might be clearer.  (Would
"most significant FOO bit" be appropriate or more confusing?), and
wondering if you might want to include some negative n examples in the
integer-length verbage and example set.

Thanks

>
>
> For the following bitwise functions, negative numbers are treated as
> infinite precision twos-complements.  For instance -6 is bits
> ...111010, with infinitely many ones on the left.  It can be seen that
> adding 6 (binary 110) to such a bit pattern gives all zeros.
>
>
>  - 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 corresponds to a multiplication by 2^CNT.  When CNT is
>      negative it's a division, and the rounding is 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.  For instance -23 is ...11101001, which shifted by
>      a CNT of -2 drops two bits to give ...111010, which is -6.
>
>           (number->string (ash #b1 3) 2)     => "1000"
>           (number->string (ash #b1010 -1) 2) => "101"
>
>  - Scheme Procedure: integer-length n
>  - C Function: scm_integer_length (n)
>      Return the number of bits necessary to represent N.
>
>      For positive N this is how many bits to the highest one bit.  For
>      negative N it's how many bits to the highest zero bit in twos
>      complement form.
>
>           (integer-length #b10101010)
>              => 8
>           (integer-length 0)
>              => 0
>           (integer-length #b1111)
>              => 4
>
>
>
> _______________________________________________
> Guile-devel mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/guile-devel

-- 
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592  F9A0 25C8 D377 8C7E 73A4




reply via email to

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