Re: Convert integer to fixed length binary string

2009-06-11 Thread casebash
Thanks, this is what I needed On Jun 11, 9:40 pm, Ulrich Eckhardt wrote: > casebash wrote: > > I know the bin function converts an int into a binary string. > > Binary string sounds ambiguous. Firstly, everything is binary. Secondly, > strings are byte strings or Unicode strings. In any case, I'm

Re: Convert integer to fixed length binary string

2009-06-11 Thread Mensanator
On Jun 11, 4:29 am, casebash wrote: > Sorry, I didn't quite make it clear. The issue isn't about limiting > the length (as I won't be using integers bigger than this). The > problem is that sometimes the output is shorter. This works also: >>> bin(15)[2:].zfill(32) '1

Re: Convert integer to fixed length binary string

2009-06-11 Thread casebash
Sorry, I didn't quite make it clear. The issue isn't about limiting the length (as I won't be using integers bigger than this). The problem is that sometimes the output is shorter. -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert integer to fixed length binary string

2009-06-11 Thread Ulrich Eckhardt
casebash wrote: > I know the bin function converts an int into a binary string. Binary string sounds ambiguous. Firstly, everything is binary. Secondly, strings are byte strings or Unicode strings. In any case, I'm not 100% sure what you mean - giving an example of input and output would help! >

Re: Convert integer to fixed length binary string

2009-06-11 Thread Mark Dickinson
On Jun 11, 10:29 am, casebash wrote: > Sorry, I didn't quite make it clear. The issue isn't about limiting > the length (as I won't be using integers bigger than this). The > problem is that sometimes the output is shorter. Is this what you're looking for? Python 2.6.2 (r262:71600, Jun 8 2009,

Convert integer to fixed length binary string

2009-06-11 Thread casebash
Hi, I know the bin function converts an int into a binary string. Unfortunately, I need to know the length of the binary string when it is being read in and len(bin(x)) depends on x. Is there any way to limit it to 4 bytes? Thanks for your assistance, Chris -- http://mail.python.org/mailman/lis