Re: How to do integers to binary lists and back

2015-05-29 Thread John Pote
On 21/05/2015 23:31, MRAB wrote: On 2015-05-21 23:20, John Pote wrote: Hi everyone. I recently had the problem of converting from an integer to its representation as a list of binary bits, each bit being an integer 1 or 0, and vice versa. E.G. 0x53 becomes [ 0, 1, 0, 1, 0, 0, 1, 1 ] This I wa

Re: How to do integers to binary lists and back

2015-05-21 Thread Ian Kelly
On Thu, May 21, 2015 at 4:31 PM, Ben Finney wrote: "{foo:d}".format(foo=foo) > '4567' "{foo:b}".format(foo=foo) > '1000111010111' Which since there's nothing else in the format string can be simplified to: >>> format(foo, "b") '1000111010111' -- https://mail.python.org/mailman/listinf

Re: How to do integers to binary lists and back

2015-05-21 Thread MRAB
On 2015-05-21 23:20, John Pote wrote: Hi everyone. I recently had the problem of converting from an integer to its representation as a list of binary bits, each bit being an integer 1 or 0, and vice versa. E.G. 0x53 becomes [ 0, 1, 0, 1, 0, 0, 1, 1 ] This I wanted to do for integers of many tens

Re: How to do integers to binary lists and back

2015-05-21 Thread Ben Finney
John Pote writes: > I recently had the problem of converting from an integer to its > representation as a list of binary bits, each bit being an integer 1 > or 0, and vice versa. Is this a homework assignment? > E.G. > 0x53 > becomes > [ 0, 1, 0, 1, 0, 0, 1, 1 ] >>> foo = 4567 >>> foo 4567 >>

How to do integers to binary lists and back

2015-05-21 Thread John Pote
Hi everyone. I recently had the problem of converting from an integer to its representation as a list of binary bits, each bit being an integer 1 or 0, and vice versa. E.G. 0x53 becomes [ 0, 1, 0, 1, 0, 0, 1, 1 ] This I wanted to do for integers of many tens, if not hundreds, of bits. Python