Hi,
I've to debug an application written by someone else (...)
An 'unsigned char' is used to be filled with data from a 'short'. If I change the source 'short' variabele type (filled somewhere) into 'unsigned char' then my appplication runs without problems.
I found out that 'short' is a 16-bit variable and I know that 'unsigned char' is a 8-bit variable, but how does conversion take place from 'short' to 'unsigned char' and how is 'short' to be interpreted as signed or unsigned?
All tips are welcome,
Henk
Actually, what you have to do is learn the language that code is written in, before barging in to change it. The questions to both your questions are right there in your C textbook.
This is a basic question on the C programming language. The rules of implicit arithmetic type conversions can be found in the ANSI C standard and in many other sources. Alternatively, you can examine the disassembly of your code to see how the compiler does the conversion (it should follow the standard rules.) My guess is that the conversion from 'short' to 'unsigned char' is done by simply discarding 8 most significant bits in the binary representation of the number, including the sign bit, and leaving the remaining 8 least significant bits as-is.