Suddenly thought of the computer's complement, now use this topic to review the relevant knowledge points
unsigned char ch =-1;
int val = ch;
The final value of Val is 255;
Converted to binary,-1 Source: 1000 0001, anti-code: 1111 1110, negative numbers in the computer is in the form of complement, 1 of the complement: 1111 1111
CH variable is unsigned, that is, the entire complement of bits are numeric digits, 1111 11,112 binary bits converted to decimal is 255, the final assignment to the integer result is naturally 255
This topic examines the computer numerical storage, for positive numbers, anti-code and complement is the same itself, for negative numbers, a little difference
Negative number of the inverse code: the original code based on the symbol bit unchanged, the value is reversed
Complement of negative numbers: Anti-code based on +1
A review of computer numerical storage Method-original code, anti-code, complement