title: Anticipating the right amount of binary bits needed to address a base10 user input
body: <p>I'm currently writing a program that takes a decimal number from the user and then outputs its binary equivalent.</p>
  
  <p>e.g. 3(base10) = 00000011(base2)</p>
  
  <p>At the moment my program is limited to only accepting a number in the range of 0-128 (8 bits required to address this or 1 Byte).</p>
  
  <p>I'd like to expand this to be able to accept much larger numbers that would require more bits to address.</p>
  
  <p>The current class looks like this:</p>
  
  <pre><code>public class Number {
      private int numberInput;
  
      public Number(int input)
      {
         this.numberInput = input;
      }
  
      public String getBinary()
      {
        StringBuilder sb = new StringBuilder();
        int maxBinary = 128;
  
        while(numberInput &gt; 0)
        {
          if(numberInput &gt;= maxBinary)
          {
              numberInput -= maxBinary;
              sb.append("1");
          }
          else
          {
              sb.append("0");
          }
          maxBinary = (maxBinary / 2);
      }
  
      while(sb.length() &lt; 8)
      {
          sb.append("0");
      }
  
      return sb.toString();
    }
  }
  </code></pre>
  
  <p>The basic operation is that it iterates over the bit places and then determines if a 1 or 0 should be placed there and once the input number has been broken down to 0, if the bit length is less than 8, it will append 0's to the output until it is an 8 bit binary "number" which will then be outputted to the console.</p>
  
  <p>Will I be able to break down numbers in a similar way when they require more than 8 bits?
  Thanks in advance</p>