Commit 892eff2c authored by Sivakorn Bupphadee's avatar Sivakorn Bupphadee

ส่งงาน week03 ขอคะแนนด้วยครับ

parent 65f83a8e
def value(v,p=4,n=3):
"""รับค่า v มาเพื่อหาค่าเป็นเลข binary -> digital.
โดยกำหนดค่าเริ่มต้น
p: เป็นจำนวนหลักที่ใช้เป้นจำนวนบวก 4 หลัก
n: เป็นจำนวนหลักที่ใช้เป็นจำนวนลบ 3 หลัก
sign bit : เป็นหลักแรกเสมอ
"""
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=4,n=3):
a = [ int(i) for i in v]
sign = -1 if a[0] == 1 else 1
return sign*sum([a[i]*2**(p-i) for i in range(1,p+n+1)])
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