Unsigned number: there are no positive or negative points, and all bits are used to represent the number itself.
Signed number: the highest bit is used to denote the positive or negative of the number, the highest bit is 1 for negative numbers, and the highest bit is 0 to indicate positive numbers.
1 . Unsigned number ---> signed number
See if the highest bit of the unsigned number is 1,
If it is not 1 (0), then the signed number is directly equal to the unsigned number;
If the highest bit of the unsigned number is 1, the unsigned number is complementary and the number is the signed Number.
2 . Signed number ---> unsigned number
See if the highest bit of the signed number is 1,
If it is not 1 (0), the unsigned number is directly equal to the signed number;
If the highest bit of the signed number is 1, then the signed number is complementary, and the resulting number is the unsigned number.
Summarize:
The conversion between the signed number and the unsigned number depends on whether the highest bit of the number to be converted is 1.
If it is not 1, then the conversion result is the number to be converted Itself;
If 1, The conversion result is the complement of the converted number (considered negative).
C-language Signed and unsigned conversions