将每8个(‘0’或‘1’)字符串转为相应的整数(用1个字节存储)
下面这个是转换为int型存储了,不是1个字节,int转char 也只能在-128~128 我需要转的超了
例如:11111111 ~~ 258
char ch;
char value = '0';
ifstream fs(filename);
ofstream of(filename2);
vector <char> code;
while (fs.peek() != EOF)
{
fs >> ch;
code.push_back(ch);
}
for (int i = 0; i < code.size(); i++)
cout << code[i];
cout << endl;
int j = 0;
for (int i = 0; i < code.size(); i++)
{
if (j!=8)
{
value = (value << 1) + (code[i] == '1' ? 1 : 0);
j++;
}
if (j == 8)
{
cout << value;
char i;
i = value+'0';
of<<i;
j = 0;
value = 0;
}
//cout << value;
}