title: negation of a number
body: <pre><code>int x=8; 
  int k=~(x); 
  
  printf(%d",k) 
  </code></pre>
  
  <p>output: 9</p>
  
  <p>The explanation for it is:</p>
  
  <pre><code>8= 00000000 00000000 00000000 00001000 
  ~8 = 11111111 11111111 11111111 11110111 
  </code></pre>
  
  <p>we are assigning it in integer hence most significant bit (MSB)is the sign bit 
  bcz MSB is 1 hence it is treated as -ve no. 
  when u try to print it then before printing compiler will take 2's complement hence it becomes : 
  2's complement of <code>(~8)=9</code> 
  2's complement of <code>11111111 11111111 11111111 11110111</code> is <code>00000000 00000000 00000000 00001000 +1 = 1001 = 9</code></p>
  
  <p>So my question is what if we do <code>k=-9</code> then if we print k, it will print -9. when does exactly it takes 2's complement</p>