【发布时间】:2016-10-26 13:26:56
【问题描述】:
我正在尝试创建一个 binary32 浮点到十进制转换器,它由 8 位的指数和 24 位的尾数组成。我有exponent = [] 和mantissa = []。如果用户输入010000111111101101000000000000000,我希望将value 的索引一到八添加到exponent,并将value 的索引九到三十二添加到mantissa。我目前有以下意大利面条代码来执行此操作:
print ("Welcome to August's floating point value to decimal converter!")
value = input("Please enter 32 bit floating value to convert.")
exponent = []
mantissa = []
exponent.append(value[1])
exponent.append(value[2])
exponent.append(value[3])
exponent.append(value[4])
exponent.append(value[5])
exponent.append(value[6])
exponent.append(value[7])
exponent.append(value[8])
print (exponent)
mantissa.append(value[9])
mantissa.append(value[10])
mantissa.append(value[11])
mantissa.append(value[12])
mantissa.append(value[13])
mantissa.append(value[14])
mantissa.append(value[15])
mantissa.append(value[16])
mantissa.append(value[17])
mantissa.append(value[18])
mantissa.append(value[19])
mantissa.append(value[20])
mantissa.append(value[21])
mantissa.append(value[22])
mantissa.append(value[23])
mantissa.append(value[24])
mantissa.append(value[25])
mantissa.append(value[26])
mantissa.append(value[27])
mantissa.append(value[28])
mantissa.append(value[29])
mantissa.append(value[30])
mantissa.append(value[31])
mantissa.append(value[32])
print (mantissa)
因此,与其单独附加每个索引,我想知道是否有一种方法可以将它们全部添加到列表中。我尝试了以下extend 方法:
exponent.extend(value[1, 2, 3, 4, 5, 6, 7, 8]) 也没有逗号
exponent.extend(value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], ) 然后我意识到extend 只接受一个参数。
exponent.extend(value[1-8]) 似乎减去了 1 和 8。
我试过exponent = {} 我相信哪个系列?然后尝试exponent.update,后跟多个带逗号的索引。然后告诉我它只支持一个论点。
关于如何将多个索引从value 添加到列表中还有其他建议吗?
【问题讨论】:
标签: python binary floating exponent mantissa