I have a char array of hex values and would like to convert them into a single integer value. I have two issues with the code I am currently using:
Problem 1: the value stored in strHex after running this is - "0927ffffffc0" when I want it to be "000927C0" - what is the reason for the extra "ffffff" being added?
Problem 2: I would like a solution to convert a char array of hex values to an integer without using stringstream if possible.
char cArray[4] = { 0x00, 0x09, 0x27, 0xC0 }; // (600000 in decimal)
std::stringstream ss;
for (int i = 0; i < 4; ++i)
{
ss << std::hex << (int)cArray[i];
}
std::string strHex = ss.str();
int nHexNumber;
sscanf(strHex.c_str(), "%x", &nHexNumber);
nHexNumber should be 600000 when converted and its giving me -64.