Insriting into a bitstream
- by evilertoaster
I'm looking for a way to efficiently insert bits into a bitstream and have it 'overflow', padding with 0's.
So for example if you had a byte array with 2 bytes: 231 and 109 (11100111 01101101), and did BitInsert(byteArray,4,00) it would insert two bits at bit offset 4 making 11100001 11011011 01000000 (225,219,24). It would be ok even the method only allowed 1 bit insertions e.g. BitInsert(byteArray,4,true) or BitInsert(byteArray,4,false).
I have one method of doing it, but it has to walk the stream with a bitmask bit by bit, so I'm wondering if there's a simpler approach...
Answers in assembly or a C derivative would be appreciated.