将整数字节转换为列表的最快方法 [英] Fastest way to convert a byte of integer into a list
问题描述
您好,
我正试图找到一种方法来转换一个整数(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?
推荐答案
7月12日下午3:34,哥斯拉< godzillais ... @ gmail.com写道:
On Jul 12, 3:34 pm, Godzilla <godzillais...@gmail.comwrote:
你好,
我正试图找到一种方法来转换一个整数(8位长的
起始者)并将它们转换成一个列表,例如:
num = 255
numList = [1,1,1,1,1,1,1,1]
with the列表中的第一个元素是最不重要的,所以
我可以继续附加到该列表而不必担心整数的大小
。我需要这样做,因为一些
函数调用可以返回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)]
7月13日上午9:54,Matimus< mccre ... @ gmail.comwrote:
On Jul 13, 9:54 am, Matimus <mccre...@gmail.comwrote:
7月12日下午3:34,Godzilla< godzillais ... @ gmail.comwrote:
On Jul 12, 3:34 pm, Godzilla <godzillais...@gmail.comwrote:
你好,
Hello,
我正试图找到一种转换整数的方法(8位长的
开始)并将它们转换为列表,例如:
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]
num = 255
numList = [1,1,1,1,1,1,1,1]
,列表的第一个元素是最不重要的,所以
,我可以继续追加到该列表,而不必担心整数的大小
。我需要这样做,因为一些
函数调用可以返回2批32位数字。我必须找到一个
的方式在列表中传输它...或者有更好的方法吗?
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 for i in range(8)]
num = 255
numlist = [num >i & 1 for i in range(8)]
谢谢matimus!我会调查一下......
Thanks matimus! I will look into it...
Godzilla< go *********** @ gmail.comwrites:
Godzilla <go***********@gmail.comwrites:
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...
numlist = lookup_table [num]
其中lookup_table是预先计算的列表列表。
numlist = lookup_table[num]
where lookup_table is a precomputed list of lists.
这篇关于将整数字节转换为列表的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!