Commit 53144a4d authored by Kittipong Maneewong's avatar Kittipong Maneewong Committed by sumet

ส่งงาน Week03

parents 238259c3 a9da5524
def value(v,p,n):
sign = -1 if v[0]==1 else 1
return sign*sum([v[i]*(2**(p-i)) for i in range(1,p+n+1)])
def values(v,p,n):
V = list(map(int,v))
sign = -1 if V[0]==1 else 1
return sign*sum([V[i]*(2**(p-i)) for i in range(1,p+n+1)])
v1 = [1, 0,0,1,1,1, 0,0,1,0]
print(v1)
print(value(v1,5,4))
print(values("1001110010",5,4))
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