Insriting into a bitstream
Posted
by evilertoaster
on Stack Overflow
See other posts from Stack Overflow
or by evilertoaster
Published on 2010-04-13T23:42:51Z
Indexed on
2010/04/13
23:42 UTC
Read the original article
Hit count: 272
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.
© Stack Overflow or respective owner