Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixed writing behaviour #16

Open
aserdobintsev opened this issue Jun 3, 2020 · 1 comment
Open

Mixed writing behaviour #16

aserdobintsev opened this issue Jun 3, 2020 · 1 comment

Comments

@aserdobintsev
Copy link
Contributor

aserdobintsev commented Jun 3, 2020

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
Copy link
Owner

Cosmo commented Jun 17, 2020

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? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants