Shouldn't be too difficult to figure out an algorithm for it... Some hints: 1) To check the rightmost bit of a number: (x % 2) // Remainder when dividing by 2) The generic form would be (x % (1 << numBits)) to get any number of bits. 2) To remove the rightmost bit: (x >> 1) // Shift right one bit 3) To add a bit to the left of a number: (x + (newBit << currentBitCount)) As for the algorithm, you know exactly how many bits are moving into and out of each byte... Each group of eight septets turns into 7 octets... So the formulae are: oct0 = s0 + ((s1 % (1 << 1)) << 7) (Start with septet 0, get 1 bit from septet 1, shift it 7 places left, and add it to septet 0) oct1 = (s1 >> 1) + ((s2 % (1 << 2)) << 6) (Shift out one bit, since we moved it to octet 0, grab 2 bits from the next byte, shift 6 places, since we're one place shorter, and add) oct3 = (s2 >> 2) + ((s3 % (1 << 3)) << 5) See the pattern? (A = this byte, B = next byte) octN = (A >> N) + ((B % (1 << (N + 1))) << (7 - N)) Do that for 7 bytes, skip the 8th byte (All 7 bits from the 8th byte would be shifted to the 7th byte), and start over.
Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)