我有一個bitstring.Bitarray,並希望從某個位置讀取到另一個位置。 我有一個for循環int變量長度,所以,比如我有:閱讀位定義的位置definded長度
length = 2
和我Bitarray看起來像:
msgstr = bitstring.BitArray(0b11110011001111110)
id = bitstring.BitArray()
m = 0
while 5 != m:
/////////////
Length changes in value part of Code
/////////////
x = 0
if m == 0:
while length != x:
id.append = msgstr[x] #msgstr is the BitArray that needs to be read
x = x + 1
m = m + 1
然後我想讀的前兩位,並將其轉換爲一個int,所以我有: id == 3
併爲下一輪時,長度值發生了變化,應該從第三位等
謝謝,切片效果很好 –