The following code
#include <sstream>
#include <iostream>
int main() {
uint8_t result = 0;
std::stringstream ss("2B");
ss << std::hex;
ss >> result;
std::cout << result;
return 0;
}
outputs 2 with GCC 6.3 and 48 with clang on macOS. Why? The correct result is 43, and clearly it fits in uint8_t and even int8_t. However, replacing uint8_t with uint16_t results in 43.