Scott wrote: > I have a buffer of "packed" "bytes" where each byte is less that > 8-bits in length. > > This buffer is generated by capturing a bitstream (LSB first) and > right shifting in to the LSB of a buffer. > > e.g. for bytes sized 7 bits, if the first byte is all ones, the second > is all zeros, and the third is all ones, > my buffer looks as such: > > 01111111 > 11000000 > xxx11111 > xxxxxxxx > ... OK, I understand this is what happens, but I don't understand why. Why not have the receiving function put them in the right order from the getgo? Is it because you have no control over it? > What I would like to do is break each "byte" out of the buffer and put > it into another buffer, e.g. > > 01111111 > 00000000 > 01111111 > 0xxxxxxx > 0xxxxxxx > ... > > > I've started writing a function (in C) to do this, but I was wondering > if anyone had anything similar (no need for me to reinvent the wheel). They may exist, but I don't recall seeing one. > Ideally, I was going to create a generic C function that would take as > parameters the input and output buffer pointers, length of the input > buffer, the size of each "byte," and where to begin processing the > first byte (e.g. if the first bit of the first byte in the buffer was > not at the LSB position, but somewhere in the middle, ex: bit 3: > xxxx1xxx). YAGNI. I would write the function to solve the problem at hand, and not worry about making it generic until you actually need to. Vitaliy -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist