[OT] Number theory [Was: A use for integer quotients]
Tim Peters
tim.one at home.com
Mon Jul 30 08:48:49 CEST 2001
[David Eppstein]
> ...
> However, I think bit twiddling is nice and continuous if instead you
> use 2-adic numbers (overcondensed tutorial: 2-adic integers are
> binary numbers where the bit sequence goes to infinity to the
> left instead of to the right, e.g. 3 1/4 = .....000011.01 -- just apply
> usual 2's complement arithmetic to these sequences and everything
> works).
>
> Of course, this doesn't do much for your attempt to make this thread
> relevant to Python again...
It does: bit-fiddling on Python longs was designed to be viewed as if on
"left-unbounded" bitstrings, with an unbounded supply of sign-bit duplicates
"to the left". All the bit-fiddling operations are consistent with this
view. They're not fully general bitstrings, though -- the only
representable bitstrings are those with a finite number of 0 bits, or a
finite number of 1 bits. Luckily <wink>, the set of representable bitsrings
is closed under the bit-fiddling operations, as well as under + - and *.
More information about the Python-list
mailing list