public long getLong(int bits) throws IOException {
        if (bits > 64) {
            throw new IllegalArgumentException("Argument \"bits\" must be <= 64");
        }
        long res = 0;
        if (endian == LITTLE_ENDIAN) {
            for (int i = 0; i < bits; i++) {
                if (getBit()) {
                    res |= (1L << i);
                }
            }
        } else {
            for (int i = bits - 1; i >= 0; i--) {
                if (getBit()) {
                    res |= (1L << i);
                }
            }
        }
        return res;
    }