Unless you are deeply concerned with efficiency, you should approach this by creating bitwise functions to address the data. Then the logic can be translated more or less directly from your requirement.
Example,
copyOneBit(dest, source, offset)
which makes it easy to code:
copyBits(dest, source, offset, numberOfBits)