Fastest way to convert a byte of integer into a list

Godzilla godzillaismad at gmail.com
Fri Jul 13 02:01:01 CEST 2007


On Jul 13, 9:54 am, Matimus <mccre... at gmail.com> wrote:
> On Jul 12, 3:34 pm, Godzilla <godzillais... at gmail.com> wrote:
>
> > 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 for i in range(8)]

Thanks matimus! I will look into it...




More information about the Python-list mailing list