Mixed writing behaviour
Opened this issue · 1 comments
aserdobintsev commented
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'.
Cosmo commented
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? 🤔