title: convert decimal to 32 bit binary?
body: <p>convert a positive integer number in C++ (0 to 2,147,483,647) to a 32 bit binary and display.</p>
  
  <p>I want do it in traditional "mathematical" way (rather than use <strong>bitset</strong> or use <strong>vector</strong> *<em>.pushback</em>* or recursive function or some thing special in C++...), (one reason is so that you can implement it in different languages, well maybe)</p>
  
  <p>So I go ahead and implement a simple program like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  int main()
  {
      int dec,rem,i=1,sum=0;
      cout &lt;&lt; "Enter the decimal to be converted: ";
      cin&gt;&gt;dec;
      do
      {
          rem=dec%2;
          sum=sum + (i*rem);
          dec=dec/2;
          i=i*10;
      } while(dec&gt;0);
  
      cout &lt;&lt;"The binary of the given number is: " &lt;&lt; sum &lt;&lt; endl;
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>Problem is when you input a large number such as 9999, result will be a negative or some weird number because sum is integer and it can't handle more than its max range, so you know that a 32 bit binary will have 32 digits so is it too big for any number type in C++?. Any suggestions here and about display 32 bit number as question required?</p>