The difference between unsigned int and int

The difference between unsigned int and int

 

foo void (void)
{
unsigned int. 6 = A;
int B = -20;
(A + B>. 6) the puts ( ">. 6"): the puts ( "<=. 6");?
}
unsigned int Problem The answer is that the output is

"> 6." The reason is that expressions signed and unsigned types for all types of the operands are converted to unsigned type automatically. Thus -20 becomes a very large positive integer, and the expression
calculated result is greater than 6.

 

Unsigned and signed numbers mixing operation. By default, the number of signed content as unsigned interpretation computing . -20 on when 0xffffffec (4294967276). Apparently (a + b> 6) holds. Output> 6.

 

 

to sum up:

   Positive anti-code and complement are the same as the original code.

   Negative inverse of the number of code symbols in addition to the original sign bit inverted you.

   Negative complement to everybody except the sign bit inverted the original code number, and then in the last plus 1  

 

Guess you like

Origin blog.csdn.net/ll148305879/article/details/92796456