Number of bits/sizeof int
Mark Wooding
mdw at distorted.org.uk
Mon Feb 2 20:19:21 EST 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