Integer to bitfield as a list

前端 未结 6 726
一向
一向 2021-02-13 01:33

I\'ve created a method to convert an int to a bitfield (in a list) and it works, but I\'m sure there is more elegant solution- I\'ve just been staring at it for to

6条回答
  •  情话喂你
    2021-02-13 02:24

    Does not work for negative values

    >>> import numpy as np
    >>> [int(x) for x in np.binary_repr(123)]
    [1, 1, 1, 1, 0, 1, 1]
    

提交回复
热议问题