private static void writeInt(BitOutputStream out, int numBits, int value) throws IOException {
		if (numBits < 0 || numBits > 32)
			throw new IllegalArgumentException();
		
		for (int i = 0; i < numBits; i++)
			out.write((byte)(value >>> i & 1));  // Little endian
	}