@staticmethod
    def twos_comp(val, bits):
        if val > 0 and val&(1<<(bits-1)) != 0:  # not ==1
            val -= 1<<bits
        return val
compute the 2's compliment of positive int value val
dataset/ETHPy150Open algorhythms/LintCode/Update Bits.py/Solution.twos_comp