1
#include <stdio.h>
int main(){
    int x = -10;
    printf("\%d\n",~x+1);

    return 0;
}

~x + 1 = > 2's complement of X .. I couldn't understand this

x = 1111 1111 1111 1010
one's complement of x [~x] - 0000 0000 0000 0101
Adding 1 to it [~x + 1] - 0000 0000 0000 0110 which is not 10 but 6. But the output above returns 10.

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
Angus
  • 12,133
  • 29
  • 96
  • 151
  • 5
    Your walkthrough of the math starts with an incorrect assumption. `1111 1111 1111 1010` isn't -10, it's -6. (Which explains why `~x+1` aka `-x` returns 6 in your walkthrough.) – Joe White Dec 31 '15 at 05:12
  • 1
    Adding to the above comment, -10 is `1111 1111 1111 0110`. – kaylum Dec 31 '15 at 05:14

0 Answers0