I have such list in Python: [1,0,0,0,0,0,0,0]. Can I convert it to integer like as I’ve typed 0b10000000 (i.e. convert to 128)?
I need also to convert sequences like [1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0] to integers (here it will return 0b1100000010000000, i.e. 259).
Length of list is always a multiple of 8, if it is necessary.
I have such list in Python: [1,0,0,0,0,0,0,0] . Can I convert it to integer
Share
You can use bitshifting:
This easily beats the “int cast” method proposed by A. R. S., or the modified cast with lookup proposed by Steven Rumbalski: