Given an arbitrary array of octets, and an offset measured in bits, the goal is to bitwise left rotate the array by the specified number of bit positions as if the entire array were a single contiguous number. Byte order is big-endian.
As an example, given the (not zero terminated) ASCII string
abcd and a shift of 5 bits. we turn this array of bytes:
01100001 01100010 01100011 01100100
into this one:
00101100 01001100 01101100 10001100
Notice that the bits propagate to the left from byte to byte and that they wrap back around.
Now that I think you've all got the idea, the rules:
- Your program should accept an arbitrary unsigned integer ("number of bits to shift" non-negative, possibly zero, limited only by the size of the standard integer type) and a raw stream of octets of arbitrary length (you may assume the length is strictly positive). How you accept these is up to you (file,stdin,parameter are all acceptable). Your program should output the shifted bytes in an analogous manner (i.e. file,stdout,return value).
- "Cut-and-paste" style code is not allowed. That is, you can't rely on your user to set the value of a certain variable before calling your code.
- The byte ordering is big-endian.
- Shortest code wins.
EDIT: It's clear now I should have restricted the input output format a bit more. The solutions that are using ASCII 0s and 1s directly aren't very interesting unfortunately.