I have an 80 element char
array and I am trying to specific elements to an integer
and am getting some number errors.
Array element 40 in hex is 0xC0. When I try assigning it to an integer
I get in hex 0xFFFFC0, and I dont know why.
char tempArray[80]; //Read in from file, with element 40 as 0xC0
int tempInt = (int)tempArray[40]; //Output as 0xFFFFC0 instead of 0x0000C0
Depending on your implementation, a char
type in C++ is either a signed
type or an unsigned
type. (The C++ standard mandates that an implementation chooses either scheme).
To be on the safe side, use unsigned char
in your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With