By using std::hex and std::dec, it is possible to parse hexadecimal from a string and convert it to a decimal number in C++. But what if the hexadecimal number is signed?
The following code for example will result 241 which is correct if the input "F1" is unsigned hex, but the result should be -15 if the input was a signed hex. Is there a C++ function that can process signed hex values?
int n;
stringstream("F1") >> std::hex >> n;
std::cout << std::dec << "Parsing \"F1\" as hex gives " << n << '\n';