Code:void load(istream& in) { letter.clear(); code_g.clear(); int x; in >> x; //no. of letters unsigned char y; vector <bool> z; unsigned char no_bits; for (int i=0;i<x;i++) { in >> y; letter.push_back(y); in >> no_bits; //the number of bits for (int j=0;j<24;j++) { if (j%8==0) in >> y; if (j<no_bits) z.push_back(y/(unsigned char)pow(2,j%8)); } code_g.push_back(z); z.clear(); } }these functions are members of a class that has a table of bits and lettersCode:void print(ostream& out) { out << letter.size(); for (int i=0;i<letter.size();i++) { out << letter[i]; out << (unsigned char)code_g[i].size(); unsigned char x=0; for (int j=0;j<24;j++) { if (j==8 || j==16) { out << x; x=0; } x |= (j < code_g[i].size() ? code_g[i][j] : 0) * (unsigned char)pow(2,j%8); } out << x; } }
a 010111
b 01
c 1111
etc...
all the letters are in the letter[] vector array. the bits are in the code_g vector array; each element of the array is another array of boolean values representing bits. ie:
vector <unsigned char> letter;
vector <vector <bool> > code_g;
i am sure the table is set up properly when created because there is another function which outputs the table in plaintext.
my problem:
void print() is supposed to output code to somewhere, like a file
void load() is supposed to receive that code and translate it back into a table. somewhere between these two functions the bitstream is being translated wrong. i think it's on load(), but i can't be sure.
any ideas on what's wrong?



LinkBack URL
About LinkBacks



