Skip to content
Discussion options

You must be logged in to vote

Hi. Yes you can modify an interpretation of a BitArray object to do what I think you're trying to do. Note that this doesn't work for a Bits class as that's immutable.

>>> a = BitArray(uint=5, length=10)
>>> a
BitArray('0b0000000101')
>>> a.u
5
>>> a.u += 11
>>> a.u
16
>>> a
BitArray('0b0000010000')

The line a.u += 11 gets the unsigned integer interpretation of the binary data, adds eleven to it, then resets the data with the new value (keeping the length the same).

Hope that helps.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by 5hayanB
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants