public BitArray(int length,byte[] a) throws IllegalArgumentException {
  if (length < 0) {
    throw new IllegalArgumentException("Negative length for BitArray");
  }
  if (a.length * BITS_PER_UNIT < length) {
    throw new IllegalArgumentException("Byte array too short to represent " + "bit array of given length");
  }
  this.length=length;
  int repLength=((length + BITS_PER_UNIT - 1) / BITS_PER_UNIT);
  int unusedBits=repLength * BITS_PER_UNIT - length;
  byte bitMask=(byte)(0xFF << unusedBits);
  repn=new byte[repLength];
  System.arraycopy(a,0,repn,0,repLength);
  if (repLength > 0) {
    repn[repLength - 1]&=bitMask;
  }
}

public BitArray ( int length , byte [ ] a ) throws IllegalArgumentException { if ( length < 0 ) { throw new IllegalArgumentException ( "Negative length for BitArray" ) ; } if ( a . length * BITS_PER_UNIT < length ) { throw new IllegalArgumentException ( "Byte array too short to represent " + "bit array of given length" ) ; } this . length = length ; int repLength = ( ( length + BITS_PER_UNIT - 1 ) / BITS_PER_UNIT ) ; int unusedBits = repLength * BITS_PER_UNIT - length ; byte bitMask = ( byte ) ( 0xFF << unusedBits ) ; repn = new byte [ repLength ] ; System . arraycopy ( a , 0 , repn , 0 , repLength ) ; if ( repLength > 0 ) { repn [ repLength - 1 ] &= bitMask ; } }
creates a bitarray of the specified size , initialized from the specified byte array . the most significant bit of a [ 0 ] gets index zero in the bitarray . the array a must be large enough to specify a value for every bit in the bitarray . in other words , 8 * a . length < = length .
