HI, all.
Here are the things I want to do :
I want to store lots of informations to a block by bits, and save it into a file.
In order to keep my file not so big, I only want to use a small number of bits to save specified information instead of a int.
For example, I want to store Day, Hour, Minute to a file.
I only want 5 bit(day) + 5 bit(Hour) + 6 bit(Minute) = 16 bit of memory for data storage.
But I can't find a efficient way to store it into a block to put it into a file.
There are some big problems in my concern :
the data length I want to store each time is not constant. It depends on the income information. So I can't just use a structure to store it.
there must not be any unused bit in my block, I've searched for some topics that mentioned that if I store 30 bits in an int(4 byte variable), then the next 3 bit I save will altomatically go into next int. but I don't want it to happen!!
I know i can use shift right, shift left to put a number to a char, and put the char into a block. but it is way too unefficient.
What I want is to have an char array that I can continue putting specified bits into it, and use write to put it in to a file.
Any resource, web pages, that can help me, please let me know.
I really want to learn how to solve this problem to make my project more perfact.
THANKS!