I have a unsigned int that was converted to a signed char like this
unsigned int b = 128;
char a[4];
a[0] = b >> 24;
a[1] = b >> 16;
a[2] = b >> 8;
a[3] = b >> 0;
Without knowing what value of b
is, can I get back the number? The method below fails for numbers greater than 128. It seems like there is some ambiguity to getting the number back from the array.
unsigned int c = 0;
c += a[0] << 24;
c += a[1] << 16;
c += a[2] << 8;
c += a[3];
cout<<c<<endl;