[英]How can I fix not all arguments converted during string formatting?
I want to change some binary streams to decimal but I got not all arguments converted during string formatting .我想将一些二进制流更改为十进制,但在字符串格式化期间并未转换所有参数。 The point is I have the result when using binaryToDecimal (10100000)
which 10100000
is the first value of my list.关键是我在使用binaryToDecimal (10100000)
时得到了结果,其中10100000
是我列表的第一个值。 But when I use binaryToDecimal (instream_chunks[0])
which is my for
loop I got the above error.但是当我使用binaryToDecimal (instream_chunks[0])
这是我的for
循环时,我得到了上述错误。 How can I fix that?我该如何解决? I am new to python sorry for my simple question.......我是 python 新手,抱歉我的简单问题......
def binaryToDecimal(binary):
binary1 = binary
decimal, i, n = 0, 0, 0
while(binary != 0):
dec = binary % 10
decimal = decimal + dec * pow(2, i)
binary = binary//10
i += 1
print(decimal)
instream = '1010000000011000000110000000001'
instream_chunks = [instream[i:i+8]for i in range (0, len(instream), 8)]
for i in range (len(instream_chunks)):
img_value = binaryToDecimal (instream_chunks[i])
You need to convert the strings to integers before using your function on them.在对它们使用函数之前,您需要将字符串转换为整数。 Like so:像这样:
def binaryToDecimal(binary):
binary1 = binary
decimal, i, n = 0, 0, 0
while(binary != 0):
dec = binary % 10
decimal = decimal + dec * pow(2, i)
binary = binary//10
i += 1
print(decimal)
instream = '1010000000011000000110000000001'
instream_chunks = [instream[i:i+8]for i in range (0, len(instream), 8)]
for i in range (len(instream_chunks)):
img_value = binaryToDecimal (int(instream_chunks[i]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.