This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: All numbers are bitarrays too
Type: enhancement Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: alexanro, rhettinger
Priority: normal Keywords:

Created on 2003-11-21 13:18 by alexanro, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg54063 - (view) Author: Alexander Rødseth (alexanro) Date: 2003-11-21 13:18
It would be nice if all numbers could be used as arrays
of bits as well.

Example:

>>> i = 10
>>> i[0] = 1
>>> print i
11
>>> print list(i)
[1, 1, 0, 1]
>>> "".join(map(lambda b:str(b), l))
'1101'
>>> for bit in i: print bit
1
1
0
1
msg54064 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004-01-01 06:22
Logged In: YES 
user_id=80475

Allowing assignments like i[o]=1 can only work for mutable
objects.   Since int is immutable, your idea would need to
be implemented as a separate extension class.

I recommend writing it first in pure python and posting it
as a cookbook recipe.  After it matures (possibly growing
other bit twiddling methods such as countbits) and has a fan
club (with some real world applications), it might warrant
coding in C.

From my experience with the setmodule, I can say that this
is not a trivial understanding, so you really have to be
sure you've worked out the API and that it meets real needs.
History
Date User Action Args
2022-04-11 14:56:01adminsetgithub: 39579
2003-11-21 13:18:36alexanrocreate