[issue3439] create a numbits() method for int and long types
Raymond Hettinger
report at bugs.python.org
Fri Dec 12 23:47:54 CET 2008
Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:
The code looks fine.
For speed, you could insert the following just before the while-loop:
while (n >= 256) {
n >>= 8;
result += 8;
}
Am not sure the "numbits" is the right-name. Is there precedent in
other languages or texts on bit-twiddling techniques? For
numbits(0b0100), I could forsee people predicting a result of 4, 3, or 1
depending on their world-view of what numbits might mean. Personally, I
tend to think in term of high-bit location or somesuch.
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3439>
_______________________________________
More information about the Python-bugs-list
mailing list