All problems
Bit Packing Decode
Problem
Unpack count integers of the given bit width from a list of byte values, where bytes are laid out least-significant first and values are packed continuously without padding.
The first value occupies the lowest bits of the stream. Assume 1 <= bits <= 8 and that the byte list holds enough bits.
Hint
Build one big integer from the bytes, then shift and mask out each field.
Test cases
case 1
in: [[170],2,4]
expected: [2,2,2,2]
case 2
in: [[1,2],8,2]
expected: [1,2]
case 3
in: [[5],4,2]
expected: [5,0]
case 4
in: [[0,0],1,8]
expected: [0,0,0,0,0,0,0,0]
case 5
in: [[129,3],1,16]
expected: [1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0]
Starter codePython
def bit_packing_decode(packed, bits, count):
# Your code here
pass5 test cases · run your code against them in the editor