That is not C, there's no foreach
in C. It might be C++, in which case the problem is that the argument to printf()
's %x
conversion specifier is being sign-extended. Your platform likely has a signed char
type.
Cast the value to unsigned char
.