1

I am using a BitArray in my python script, and I was wondering if there is a way to change the indexes order of the BitArray that I create. Right now the indexes are from 0 to N-1 where N is the number of bits. Is there away to change the indexes to go from N-1 to O?

dataBits = BitArray('0b10100000')
print(dataBits[0])

This above two lines return the first bit True because the order of indexes is from 0 to N-1. Can I change the order of indexes for this to return the last bit False?

3
  • What is returning anything True or False? Commented Nov 14, 2019 at 17:35
  • 1
    It may be effective to subclass the BitArray class and add a custom method that allows you to achieve that Commented Nov 14, 2019 at 17:39
  • 1
    Is it acceptable to reverse the bits before you create your BitArray? IE: dataBits = BitArray('10100000'[::-1])? Otherwise, you should subclass and implement your own __getitem__ and __iter__ methods. The first is preferable since there might be other methods in BitArray that depend on the order and might lead to "unexpected" behavior. Also, where is the documentation for the BitArray library you're using? Commented Nov 14, 2019 at 17:48

1 Answer 1

0

Yes. What you're looking for is the module variable lsb0:

bitstring.lsb0 = True
dataBits = bitstring.BitArray('0b10100000')
print(dataBits[0])

Prints out False.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.