1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
int HexByteStringToInt(const string & strHB)
{
return (strHB[0]-'0')*16 + strHB[1]-'0';
}
int main(int argc, char * argv[]) {
ofstream myFile;
ifstream file(argv[1], ios::in);
myFile.open(argv[2], ios::out | ios::binary);
char * buffer[BUFFER_SIZE];//When I did it with char it worked correctly with this. = {0x58, 0x45, 0x5, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00};
char * temp = " ";
int len = sizeof(buffer);
if(file.is_open())
{
for(int i = 0;!file.eof(); ++i)
{
file >> buffer[i];
buffer[i] = (char *)HexByteStringToInt(buffer[i]);
}
}
file.close();
myFile.write((char *)buffer, BUFFER_SIZE);
myFile.close();
return 0;
}
|