title: Converting to binary in C++
body: <p>I made a function that converts numbers to binary. For some reason it's not working. It gives the wrong output. The output is in binary format, but it always gives the wrong result for binary numbers that end with a zero(at least that's what I noticed..)</p>
  
  <pre><code>unsigned long long to_binary(unsigned long long x)
  {
      int rem;
      unsigned long long converted = 0;
  
      while (x &gt; 1)
      {
          rem = x % 2;
          x /= 2;
          converted += rem;
          converted *= 10;
      }
  
      converted += x;
  
      return converted;
  }
  </code></pre>
  
  <p>Please help me fix it, this is really frustrating..</p>
  
  <p>Thanks!</p>