def ref(i, s):
            mask = (1 << input_width) - 1
            if (i >> input_width - 1) & 0x1 == 0x1:
                return ((~mask | i) >> s) & mask  # negative number
            else:
                return (i >> s) & mask  # positive number