Number of bits/sizeof int

Mark Wooding mdw at distorted.org.uk
Tue Feb 3 02:19:21 CET 2009


John Machin <sjmachin at lexicon.net> writes:

> 3 can be represented in 2 bits and at the same time -3 can be
> represented in 2 bits?? But 2 bits can support only 2 ** 2 == 4
> different possibilities, and -3 .. 3 is 7 different integers.

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.

>>   ## Find upper bound of the form 2^(2^n) >= x.
>
> Possibly you mean 2 ** ( 2 ** n) >= x

I write maths in comments, not Python.  Feel lucky I didn't write it in
LaTeX.

-- [mdw]



More information about the Python-list mailing list