would any of you know the method call to convert an integer to an unsigned char??
I've been looking forever and I cant seem to find it.
Thanks everyone
would any of you know the method call to convert an integer to an unsigned char??
I've been looking forever and I cant seem to find it.
Thanks everyone
edit: Characters and integers are very interchangeable without the need for casting.Code:int myInt; unsigned char myChar; myChar = (unsigned char)myInt;
The only thing you have to watch for is the possible lost of information due to casting. if you cast an int to a char, and the value is too big (>= 256) then you'll lose information.
One question about this.Originally Posted by sean_mackrory
Explicit casting isn't really neccessary here because; it's automatically, implicitly casted by the compiler just right before assignment to myChar. So, using the above example, The same results can be achieved like so:
int myInt;
unsigned char myChar;
myChar = myInt; // implicit cast done automatically
Correct?
Correct. But it is still good practice to cast just in case the compiler doesn't