I am not used to binaries and I am trying to figure this out. I managed to save integers and unsigned char, and read them without any problems. Now, when I try to save some booleans, I see that each of my bools occupies exactly 1 octet in my file, which seems logical, since a single bool is stored in char data (correct me if I am "wrong!).
But since I will have 3 or 4 bools for serialization, I suppose it is a waste to store them like this: 00000001 00000001 00000000, for example, when I could have 00000110. I think to get this I have to use the bitwise operation but I'm not very good with them ... so can someone tell me:
- How to save up to 8 bools in one octet using bitwise manipulations?
- How to transfer correct values (up to 8 bools) from one octet using bitwise manipulation?
- (And, a bonus question, can anyone recommend a simple, non-mathematical-oriented mind like mine, a bit of manipulation tutorial, if that exists? All that I found, I understood, but could not put into practice .. .)
I use C ++, but I assume that most C-syntax languages will use the same kind of work.
source
share