public void toBytes(int bitOffset, byte[] array, int offset, int numBytes) {
    for (int i = 0; i < numBytes; i++) {
      int theByte = 0;
      for (int j = 0; j < 8; j++) {
        if (get(bitOffset)) {
          theByte |= 1 << (7 - j);
        }
        bitOffset++;
      }
      array[offset + i] = (byte) theByte;
    }
  }
public void toBytes ( int bitOffset , byte [ ] array , int offset , int numBytes ) { for ( int i = 0 ; i < numBytes ; i ++ ) { int theByte = 0 ; for ( int j = 0 ; j < 8 ; j ++ ) { if ( get ( bitOffset ) ) { theByte |= 1 << ( 7 - j ) ; } bitOffset ++ ; } array [ offset + i ] = ( byte ) theByte ; } }
@param bitOffset first bit to start writing
@param array array to write into. Bytes are written most-significant byte first. This is the opposite
of the internal representation, which is exposed by {@link #getBitArray()}
@param offset position in array to start writing
@param numBytes how many bytes to write