title: I have to use a while loop to convert decimal into binary in Java
body: <p>I have to manually convert decimal numbers into binary, but have to output from the range of 1-256 (so no user input). I believe I just take the variable for incrementing the decimal up to 256 and using that as the input for the binary conversion, but I keep getting an infinite loop. I am not allowed to use the binary conversion function so I have to convert manually.</p>
  
  <pre><code>int decimal;
  for (decimal = 1; decimal &lt;= 256; decimal++) //this is how i get from 1-256
  
  //this is the binary where i keep getting the infinite loop
  int binaryNumber = 0;
          while (decimal &gt; 0) {
              decimal = decimal / 2;
              binaryNumber = (decimal % 2) + binaryNumber;
              }
          System.out.println(binaryNumber);
  </code></pre>
  
  <p>what am I doing wrong, thanks?</p>