How to create an array of bits in Python?

Viewed 81502

How can I declare a bit array of a very large size, say 6 million bits?

5 Answers

Quite easily

bitarray60000 = 1<<60000

With that, you can use bitshift operator to your heart content. For instance, position 2 set True would be:

bitarray60000 | 1<<2

Getting bit from position 2

bitarray60000 & 1<<2

I guess the idea is quite simple. Though some operations might be tricky.

Related