Commit 122369ee authored by tanakrit's avatar tanakrit Committed by Patiphan Marak

ส่งงาน assingment ครับ

parents f4270624 161714df
#pos = input("pos :")
#neg = input("neg :")
def value(v,p,n):
def value(v,pos=4,neg=3):
sign = -1 if v[0] == 1 else 1
return sign * sum([v[i]*2**(p - i)for i in range(1,p+n+1)])
v = [0,0,1,1,1,1,0,1]
return sign * sum([v[i]*2**(pos - i)for i in range(1,pos+neg+1)])
v = [0,0,0,0,1,0,1,1]
print(value(v,4,3))
def values01(v,p,n):
def values01(v,pos=5,neg=3):
bos = list(map(int,v))
sign = -1 if bos[0] == 1 else 1
return sign * sum([bos[i] * 2 ** (p - i) for i in range(1, p + n + 1)])
return sign * sum([bos[i] * 2 ** (pos - i) for i in range(1, pos + neg )])
print(values01('00101101', 4, 3))
print(values01('00001010', 5, 3))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment