(val, bits)
return val
Retuns the 2-complemented value of val assuming bits word width
Retuns the 2-complemented value of val assuming bits word width
Retuns the 2 - complemented value of val assuming bits word width
def twos_complement(val, bits):
    """Retuns the 2-complemented value of val assuming bits word width"""
    if (val & (1 << (bits - 1))) != 0: # if sign bit is set
        val = val - (2 ** bits)        # compute negative value
    return val
def twos_complement ( val , bits ) : if ( val & ( 1 << ( bits - 1 ) ) ) != 0 : # if sign bit is set val = val - ( 2 ** bits ) # compute negative value return val