Brian Adkins <lojicdotcomNOSPAM@gmail.com> wrote:
+---------------
| Rob Warnock wrote:
| > Which, after learning a little more CL, should have
| > resulted in just using CL's builtin LOGCOUNT instead... ;-} ;-}
|
| Cool. Although, doesn't that only work for half the values
| (i.e. ones with MSB off) ?
+---------------
What is this "MSB" thing of which you speak?!? ;-} ;-}
Unlimited-precision integers don't *have* an
"MSB" per se. If you really, really need a
finite-width integer, then force it to be such:
(logcount (logand x #.(1- (ash 1 +word-width+))))
E.g.:
> (defparameter +word-width+ 32)
+WORD-WIDTH+
> (let ((x -375))
(list (logcount x) ; For negative values, counts zeros instead.
(logcount (logand x #.(1- (ash 1 +word-width+))))))
(6 26)
>
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607