deftostring(list): str = '' for i in range(len(list)): str = str + '{n}'.format(n=list[i]) return str
deffan(n): if n == 1: return0 else: return1
defzhen2yuan(zhen): yuan = [] flag = False for i in range(len(zhen)): if i == 0: if zhen[i] == '-': yuan.append(1) else: yuan.append(0) else: if zhen[i] == '.': flag = True if flag: if zhen[i] == '0': yuan.append(0) elif zhen[i] == '1': yuan.append(1) return yuan
defyuan2bu(yuan): if yuan[0] == 0: return yuan bu = [] flag = 0 for i in range(1, len(yuan)): if yuan[len(yuan) - i] == 1: flag = len(yuan) - i break
bu.append(yuan[0])
count = 0 for i in range(1, len(yuan)): if i < flag: bu.append(fan(yuan[i])) else: bu.append(yuan[i]) if yuan[i] == 0: count += 1
if count == len(yuan) - 1: bu[0] = 0
return bu
defbianbu(bu): bianbu = [] flag = 0 for i in range(1, len(bu)): if bu[len(bu) - i] == 1: flag = len(bu) - i break
for i in range(len(bu)): if i < flag: bianbu.append(fan(bu[i])) else: bianbu.append(bu[i])
return bianbu
deftwofu(input): twofu = [] twofu.append(input[0]) twofu.append(input[0]) for i in range(1, len(input)): twofu.append(input[i])
return twofu
deftwofuadd(A, B): for i in range(len(A)): A[i] += B[i]
for i in range(len(A)): if i != len(A) - 1: A[len(A) - i - 2] += (int)(A[len(A) - i - 1] / 2) A[len(A) - i - 1] = (int)(A[len(A) - i - 1] % 2) return A
""" -0.1101 -0.1011 """ if __name__ == '__main__':
# 数据输入 # X = input() # Y = input() X = '-0.1101' Y = '0.1011'
B = twofu(Xbu) # 双符号位X补 fanB = twofu(bianbu(Xbu)) # 双符号位-X补 C = Ybu # Y补
# 计算开始 print("步数 条件 操作 A C Cn+1") for step in range(len(C)):
if step == 0: C.append(0) print(" CnCn+1 {A} {C} {Cnp1}".format(A=tostring(A), C=tostring(C[:-1]), Cnp1=C[-1])) else: t = [] t.append(A[len(A) - 1]) for i in range(len(C) - 1): t.append(C[i]) C = t
for i in range(3): A[len(A) - i - 1] = A[len(A) - i - 2] A[2] = A[1] print(' -> {A} {C} {Cnp1}'.format(A=tostring(A), C=tostring(C[:-1]), Cnp1=C[-1]))