Signed and unsigned variables
What is the proper method to cast from an unsigned to a signed variable?
For example, suppose that u is an unsigned int and i is a signed int.
When u is 0, i should be -32768.
When u is 32768, i should be 0.
When u is 65535, i should be 32767.
Which of the following is correct:
i = (unsigned int) u or
i = (unsigned int) (u - 32768)?
Thanks,
David
|