title: Subtract two numbers without using arithmetic operators
body: <p>The problem that I am facing is :-</p>
  
  <p>How does the logic of bitwise operators are working in the code below?</p>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int subtract(int x, int y)
  {
      while (y != 0)
      {
          int borrow = (~x) &amp; y;
          x = x ^ y;
          y = borrow &lt;&lt; 1;
      }
      return x;
  }
  
  int main()
  {
      int x = 29, y = 13;
      printf("\nx - y is %d", subtract(x, y));
      return 0;
  }
  </code></pre>
  
  <p>How is the function subtract(x,y) is working?</p>