问题描述
您好,
我正试图找到一种方法来转换一个整数(8位长的
初学者)并将它们转换为一个清单,例如:
num = 255
numList = [1,1,1,1,1,1,1,1]
,列表中的第一个元素是最不重要的,所以
我可以继续附加到该列表而不必担心
整数的大小。我需要这样做,因为一些
函数调用可以返回2批32位数字。我必须找到一个
方式在列表中传输它...或者有更好的方法吗?
Hello,
I''m trying to find a way to convert an integer (8-bits long for
starters) and converting them to a list, e.g.:
num = 255
numList = [1,1,1,1,1,1,1,1]
with the first element of the list being the least significant, so
that i can keep appending to that list without having to worry about
the size of the integer. I need to do this because some of the
function call can return a 2 lots of 32-bit numbers. I have to find a
way to transport this in a list... or is there a better way?
推荐答案
num = 255
numlist = [num> i& 1我在范围内(8)]
num = 255
numlist = [num >i & 1 for i in range(8)]
num = 255
numlist = [num> i& 1 for i in range(8)]
num = 255
numlist = [num >i & 1 for i in range(8)]
谢谢matimus!我会调查一下......
Thanks matimus! I will look into it...
谢谢matimus!我将调查它...
Thanks matimus! I will look into it...
numlist = lookup_table [num]
其中lookup_table是预先计算的列表列表。
numlist = lookup_table[num]
where lookup_table is a precomputed list of lists.
这篇关于将整数字节转换为列表的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!