Hello!
I need to convert ASCII characters into strings of hex values.
I'm currently designing a program that must open a file, read its hex values, and react accordingly. I'm having trouble figuring out how to read from my file and store the 8-bit hex values in an array. Currently, I am using this code:
Currently, the string just stores an ASCII character.Code:// reading a complete binary file #include <iostream> #include <fstream> using namespace std; ifstream::pos_type size; char * memblock; int main () { ifstream file ("test.bin", ios::in|ios::binary|ios::ate); if (file.is_open()) { size = file.tellg(); memblock = new char [size]; file.seekg (0, ios::beg); file.read (memblock, size); file.close(); cout << "the complete file content is in memory\n\n"; // store the hex value of the first character into a string string hex1 = memblock[0]; delete[] memblock; } else cout << "Unable to open file"; return 0; }
Obviously, there is no conversion from character to hex in this code. I've tried several things, and none have worked for me. Is there some way I can directly input a file as a hex file, have the array directly store the values as hex strings, or convert the array into an array of hex strings?
(Oh, and I don't need a "0x" or "h" in values like "0xFF" or "FFh". This will just complicated what I'm going to be doing.)



LinkBack URL
About LinkBacks



CornedBee