I'm looking to change a vector of doubles into unsigned chars using c++. To make sure it works I wrote:
unsigned char x = 0;
double y = 4.6;
x = (unsigned char) y;
printf("%d", y);
cout << endl << "the char of 4.6 is: " << x;
getchar();
but instead of the char being equal to 4 or 5 I get a huge number like 1717986918 or a diamond symbol with cout.
I assume this is because its interpreting 4.6 as '4.6' but is there a way to save it so it just becomes an unsigned char of near equal value?