Hi, I could find the code to convert a hexadecimal string into a signed int (using strtol), but I can't find something for short int (2 bytes). Here' my piece of code :
while (!sCurrentFile.eof() )
{
getline (sCurrentFile,currentString);
sOutputFile<<strtol(currentString.c_str(),NULL,16)<<endl;
}
My idea is to read a file with 2 bytes wide values (like 0xFFEE), convert it to signed int and write the result in an output file. Execution speed is not an issue.
I could find some ways to avoid the problem, but I'd like to use a "one line" solution, so maybe you can help for this :)
Edit : The files look like this :
0x0400
0x03fe
0x03fe
etc...
Edit : I already tried with the hex operator, but I still have to convert the string to an integer before doing so.
myInt<<std::hex<<currentString.c_str(); //This won't work as currentString is no integer.
Thanks to ChrisV, the answer is:
sscanf(currentString.c_str(),"%hx",&myVar);
sOutputFile << myVar << endl;