title: How to convert a double into an unsigned char?
body: <p>I'm looking to change a vector of doubles into unsigned chars using c++.
  To make sure it works I wrote:</p>
  
  <pre><code>unsigned char x = 0;
  double y = 4.6;
  x = (unsigned char) y;
  printf("%d", y);
  cout &lt;&lt; endl &lt;&lt; "the char of 4.6 is: " &lt;&lt; x;
  getchar();
  </code></pre>
  
  <p>but instead of the char being equal to 4 or 5 I get a huge number like 1717986918
  or a diamond symbol with cout.</p>
  
  <p>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?</p>