Exception in thread "main" java.lang.StringIndexOutOfBoundsException:
<p>In the following</p>

<pre><code>public class Register {

  private int numberOfBits;
  private int regValue;
  private Bit [] register;

  public void main (String [] args) {
     String binaryValue = Integer.toBinaryString(regValue);
     System.out.println(binaryValue);
     int binaryLength = binaryValue.length();
     int blankSpace = numberOfBits - binaryLength;
  }
  public Register(int numberOfBits) {

     this.numberOfBits = numberOfBits;
     this.register = new Bit [numberOfBits];

     for(int i=0; i &lt; numberOfBits; i++) {
        register[i] = new Bit();
     }

  }

  public Register(int numberOfBits,int registerValue) {

     this.numberOfBits = numberOfBits;
     this.regValue = registerValue;
     this.register = new Bit[numberOfBits];

     String registerString = Integer.toBinaryString(this.regValue);
     for(int i=0; i &lt; numberOfBits; i++) {
        this.register[i] = new Bit(registerString.charAt(i));
     }
  }
</code></pre>

<p>an <code>StringIndexOutOfBounds</code> exception is thrown. Tried doing 'and' test for the for loops to no avail. Basis of program is to create arrays of base 2 numbers. </p>
