public boolean pad(int width) throws IOException {
        boolean result = true;
        int gap = (int) this.nrBits % width;
        if (gap < 0) {
            gap += width;
        }
        if (gap != 0) {
            int padding = width - gap;
            while (padding > 0) {
                if (bit()) {
                    result = false;
                }
                padding -= 1;
            }
        }
        return result;
    }