I'm trying to create an array of bits in python that are two binary numbers into a fixed width.
For eg.
[11,90] ----> 0000101101011010
What I've tried/ Problems I've encountered:
bin(11)=> 0b1010 (which is not the fixed width I need)String manipulation using format
'{0:11b}'.format(8)(this works but I'd like to avoid converting to strings and back if I can. It seems like a lot of overhead to do essentially a shift and add)
0b0000101101011010from11and90?binreturns a string. I wouldn't worry about the overhead unless you actually see it causing problems, it's unlikely to matter much. If you are worried, then you should build your ownlists ofTrueandFalse, which are as close as you are likely to get to a bit array.'{:0>8b}{:0>8b}'.format(x, y)should be sufficient1011, and00001011is the first half of the number, 90 is1011010and01011010is the second half. So it seems as if they want to convert numbers in a list to binary, add 0's to the front until each is 8 bits long, then append them together.a = 11 << 8 | 90, thenbin(a)produces0b101101011010