Does a computer always use a two-padding method to represent a negative number?

Please review the following code and help me understand it.

int a=1;
int b=~1;
printf("%d",b);

Output:

 -2

Thus, this means that 1 = (00000001) on the transition ~ produces (11111110), which is 2 in addition to the number 2 and, therefore, -2 is the answer. So 100 will always be considered -4, but not 4?

+4
source share
2 answers

Does a computer always use a 2-part method to represent a negative number?

No.

1 ( ~ 1 == -0), " " ( ~ 1 == -127), "" (, "unsigned value - " ~ 1 == 127). .

-, , (IEEE-754) ; " " ( ) "" ( ).

+2

, , . - 100? , 100 -4.

, , 1 - 0s ( , ), . 4.

, C ++ int, 8 , , . (, "" - , , , , int, , 16 . 3 struct, , .) int b=~1; 11111110; 16 , , 32 .
0

Source: https://habr.com/ru/post/1691314/


All Articles