title: Merge binary Strings and Insert bits in C
body: <p>Function insertBits</p>
  <p>X and Y are two integer values.</p>
  <p>The function insertBits must insert all the bits of Y after the last set bit in X.
  Then the function must return an integer representing the revised value of X.</p>
  <pre><code>Input:
  
  10 14
  
  Output:
  
  188
  
  Explanation:
  
  10 -&gt; 1010
  14 -&gt; 1110
  
  After inserting 1110 after the last set bit in 1010 the binary representation of X becomes 10111100.
  The decimal equivalent of 10111100 is 188.
  
  
  Input:
  
  152 9
  
  Output:
  
  2504
  
  Explanation:
  
  152 -&gt; 10011000
  9 -&gt; 1001
  
  After inserting 1001 after the last set bit in 10011000, the binary representation of X becomes 100111001000.
  The decimal equivalent of 100111001000 is 2504.
  
  </code></pre>
  <p>This is my code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  long bin(long n)
  {
      long d,r,binary=0;
      d=n;
      int temp=1;
      while(n!=0)
      {
          r=n%2;
          n=n/2;
          binary=binary+r*temp;
          temp=temp*10;
      }
      return binary;
  }
  
  
  int insertBits(int X, int Y)
  {
      bin(X);
      bin(Y);
  
       ///
      
  }
  
  int main()
  
  {
  
      int X, Y;
      scanf(&quot;%d %d&quot;, &amp;X, &amp;Y); 
      printf(&quot;%d&quot;, insertBits(X, Y)); 
      return 0;
  
  }
  
  </code></pre>
  <p>I converted decimal into binary. But I don't know how to insert the bits in X.</p>