T
Taylor Howell
Hello all,
I have a delima. I have 8 5bit numbers that I need to pack into one (or
more) variables. They then must be written (exactly 40bits (5Bytes)) to a
file and have the ability to be put back into memory and then get the 5bit
numbers out again. As I am not by any means proficient in C++ (still
learning) I don't know how to go about doing this correctly. The way I was
planning to do it is as follows:
1. create a character array of 5 chars.
2. create a long long pointer to the array.
3. using shift operators, pack my numbers into the array.
4. write the character data to file. this will lop off any extra
data from the long long
5. read the data back into a different character array.
6. move the pointer to the new array.
7. use bitwise operators to transfer five bits to new int
8. shift the pointer and do 7 again until done.
.... Please don't laugh ...
When 4 is done I read the file with a hex editor and all it is garble. Its
not the bits I'm expecting...
Anyway, if you know of any better way of doing this please point me in the
right direction. I don't want the answer though. I want to learn not just
cut and paste, and any help would be greatly appreciated!
Thanks
Taylor Howell
I have a delima. I have 8 5bit numbers that I need to pack into one (or
more) variables. They then must be written (exactly 40bits (5Bytes)) to a
file and have the ability to be put back into memory and then get the 5bit
numbers out again. As I am not by any means proficient in C++ (still
learning) I don't know how to go about doing this correctly. The way I was
planning to do it is as follows:
1. create a character array of 5 chars.
2. create a long long pointer to the array.
3. using shift operators, pack my numbers into the array.
4. write the character data to file. this will lop off any extra
data from the long long
5. read the data back into a different character array.
6. move the pointer to the new array.
7. use bitwise operators to transfer five bits to new int
8. shift the pointer and do 7 again until done.
.... Please don't laugh ...
When 4 is done I read the file with a hex editor and all it is garble. Its
not the bits I'm expecting...
Anyway, if you know of any better way of doing this please point me in the
right direction. I don't want the answer though. I want to learn not just
cut and paste, and any help would be greatly appreciated!
Thanks
Taylor Howell