[Tutor] Shifting arrays as though they are a 'word'
steve at pearwood.info
Sat Oct 6 02:42:58 EDT 2018
On Fri, Oct 05, 2018 at 04:17:53PM -0400, Chip Wachob wrote:
> I was not able to find any answers in the archive on this one.
> I'm wondering if this task can be done in a better way than what I've
> I have an array of bytes. Up to 64, which makes for 512 bits.
> I am reading these bytes in serially, and once I have a collection of
> them, I want to shift them by 'n' bits. The size of the array and the
> number of bits are both variable up to the limit of 64/512.
Code speaks much more strongly than description. Can you demonstrate an
- the actual data you have;
- the result you want;
- what you've tried?
The answers we give will be very different according to what you have,
data = [0, 1, 2, 3, 4, 5, 6, 7] # eight bytes in a list
data = b"\0\x01\x02\x03\x04\x05\x06\x07" # eight bytes in a bytes object
data = 0x0001020304050607 # eight bytes in an int
More information about the Tutor