How to create an array of bits in Python?

后端 未结 5 1257
无人及你
无人及你 2020-12-08 10:10

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

5条回答
  •  借酒劲吻你
    2020-12-08 10:34

    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.

提交回复
热议问题