public int look(int bits) {
        int ret;
        int m = mask[bits];

        bits += endbit;

        if (endbyte + 4 >= storage) {
            if (endbyte + (bits - 1) / 8 >= storage) {
                return (-1);
            }
        }

        ret = ((buffer[ptr]) & 0xff) >>> endbit;
        if (bits > 8) {
            ret |= ((buffer[ptr + 1]) & 0xff) << (8 - endbit);
            if (bits > 16) {
                ret |= ((buffer[ptr + 2]) & 0xff) << (16 - endbit);
                if (bits > 24) {
                    ret |= ((buffer[ptr + 3]) & 0xff) << (24 - endbit);
                    if (bits > 32 && endbit != 0) {
                        ret |= ((buffer[ptr + 4]) & 0xff) << (32 - endbit);
                    }
                }
            }
        }
        return (m & ret);
    }