Number of bits/sizeof int

Mark Dickinson dickinsm at gmail.com
Tue Feb 3 11:19:21 CET 2009


On Feb 3, 1:19 am, Mark Wooding <m... at distorted.org.uk> wrote:
> Yeah, I made some arbitrary choices about what to do with non-positive
> inputs.  If you prefer other answers, use 'em.  My ones work well with
> signed-magnitude representations where the sign is stored separately.

Not *that* arbitrary:  they're the same choices that were made
(after some discussion) for the int.bit_length method, which is
what the OP was looking to replace.  They're also identical
to the choices that Mathematica made for its BitLength function...

As Mark says, this seems a natural choice for sign-magnitude
representation, which is what almost every bignum library
seems to use under the hood.

Mark



More information about the Python-list mailing list