When one performs a bitwise operation on an arithmetic type smaller than int, it is automatically promoted to int.
std::uint8_t a = 42;
auto b = a | 0x0f;
// b will be of type int
What I haven't been able to determine is what exactly goes on during this promotion, specifically since it is being converted from an unsigned integer to a signed integer. Will the numerical value of a remain consistent, potentially changing the binary representation? Or will the binary representation remain consistent, potentially resulting in a different numeric value?
Is there a reason that the value would be promoted to int rather than unsigned int? The latter wouldn't cause any of this confusion.
42is presumedintandint | intisint? I'd try witha | 0x0f.int?intunless some qualifying suffix is added.