You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On line 477 the original data is unpacked and shifted to the left 2 bits
data = data.astype(np.uint16) << 2
That's fine, as you're shifting everything to facilitate easier unpacking in the following lines
for byte in range(4):
data[:, byte::5] |= ((data[:, 4::5] >> (byte * 2)) & 3)
Which essentially says "every byte is made by the combination of the original byte shifted to the left 2 (from before), with the 5th byte's lowest 2 bits added on".
However, all the bytes were shifted by two, from above, so the 5th byte also contains shifted byte data. Taking for example byte = 0, so we're looking at the first byte, this essentially says "the 0th byte is the combination of itself shifted to the left, and the lowest two bits of the 4th (zero-indexed) byte, which is currently 0 because of the previous shift operation."
Should the code not instead be
for byte in range(4):
data[:, byte::5] |= ((data[:, 4::5] >> ((byte + 1) * 2)) & 3)
To make it even clearer, if we had this data representing the first byte and the 5th byte of some set
0000 0001 <- 1st byte
0000 0011 <- 5th byte
The shift by two results in 16 bit data looking like
On line 477 the original data is unpacked and shifted to the left 2 bits
data = data.astype(np.uint16) << 2
That's fine, as you're shifting everything to facilitate easier unpacking in the following lines
Which essentially says "every byte is made by the combination of the original byte shifted to the left 2 (from before), with the 5th byte's lowest 2 bits added on".
However, all the bytes were shifted by two, from above, so the 5th byte also contains shifted byte data. Taking for example
byte = 0
, so we're looking at the first byte, this essentially says "the 0th byte is the combination of itself shifted to the left, and the lowest two bits of the 4th (zero-indexed) byte, which is currently 0 because of the previous shift operation."Should the code not instead be
To make it even clearer, if we had this data representing the first byte and the 5th byte of some set
The shift by two results in 16 bit data looking like
On the first iteration of the loop, byte is
0
, so the line readsOr simplified
The bitwise AND with
3
on the 5th byte looks likeWhen it should look lke
Hopefully that makes sense. Let me know if I missed something.
Followup:
Tested against the output looking at the lowest bits to confirm:
Every fourth byte ends in
00
.The text was updated successfully, but these errors were encountered: