unsigned long j = 0;
int count = 0;
char Hex[3];
unsigned char swapHex[8],*buffer = NULL;
while (getline(input, line)) {
for (int i = 0; i < line.length() / 8; i++) {
string sub = line.substr(i * 8, 8);
bitset<8> set(sub);
sprintf(Hex, "%02X", set.to_ulong());
long val = strtol(Hex, NULL, 16);
swapHex[count] = (unsigned char)val;
count++;
if(count == 8) {
for(count = 7; count >= 0; count--) {
buffer[j] = swapHex[count];
j++;
}
count = 0;
}
}
}
C++语言 将二进制数据按行读取转换成字节数组
于 2019-12-16 11:07:59 首次发布