BinaryKit icon indicating copy to clipboard operation
BinaryKit copied to clipboard

Mixed writing behaviour

Open aserdobintsev opened this issue 5 years ago • 1 comments

Hi Devran, could you help me to understand, is it intended writing behaviour that divides writing with bits and bytes?

For example:

var bin = Binary(bytes: [])
bin.writeBit(bit: 1)
bin.writeByte(8)

I would expect the binary is 0b1000_0100_0000_0000 - padded with zeros to the end of the byte. The Actual result is 0b1000_0000_0000_1000 - written byte adde as next but bit cursor still points to the position '1'.

aserdobintsev avatar Jun 03 '20 12:06 aserdobintsev

Hi @aserdobintsev, to be honest I always wondered what the best result might look like — and never had a good answer.

In the end I thought: Every time I write a bit, I should also fill up the other remaining 7 bits in order to get predictable results and be able to add other bytes.

Does that makes sense? 🤔

Cosmo avatar Jun 17 '20 16:06 Cosmo