I am using the following code to convert the raw data values to a hexstring so I can find some information. But I am getting FFFFFFFF where I was supposed to get FF.
For example, the result should be "FF 01 00 00 EC 00 00 00 00 00 00 00 00 00 E9", but I am getting "FFFFFFFFF 01 00 00 FFFFFFEC 00 00 00 00 00 00 00 00 00 FFFFFFE9".
Does anyone know what is happening here?
std::vector<unsigned char> buf;
buf.resize( ANSWER_SIZE);
// Read from socket
m_pSocket->Read( &buf[0], buf.size() );
string result( buf.begin(), buf.end() );
result = ByteUtil::rawByteStringToHexString( result );
std::string ByteUtil::int_to_hex( int i )
{
std::stringstream sstream;
sstream << std::hex << i;
return sstream.str();
}
std::string ByteUtil::rawByteStringToHexString(std::string str)
{
std::string aux = "", temp = "";
for (unsigned int i=0; i<str.size(); i++) {
temp += int_to_hex(str[i]);
if (temp.size() == 1) {
aux += "0" + temp + " "; // completes with 0
} else if(i != (str.size() -1)){
aux += temp + " ";
}
temp = "";
}
// System.out.println(aux);
return aux;
}
UPDATE: Debugging, I noticed that the int_to_hex is returning FFFFFFFF instead of FF. How can I fix that?