Re: howto print binary number

2008-05-07 Thread castironpi
On May 7, 4:03 pm, Joel Bender <[EMAIL PROTECTED]> wrote: > > Python 3.0 has such a formatting operation, but Python 2.x does not.   > > However it's not hard to write. > > Indeed.  Refraining from using named lambdas: > >      >>> def bin(x): >      ...     return ''.join(x & (1 << i) and '1' or '

Re: howto print binary number

2008-05-07 Thread Ivan Illarionov
On Wed, 07 May 2008 13:13:40 -0700, dmitrey wrote: > hi all, > could you inform how to print binary number? I.e. something like > > print '%b' % my_number > > it would be nice would it print exactly 8 binary digits (0-1, with > possible start from 0) > > Thank you in advance, D Here it is: de

Re: howto print binary number

2008-05-07 Thread Joel Bender
Python 3.0 has such a formatting operation, but Python 2.x does not. However it's not hard to write. Indeed. Refraining from using named lambdas: >>> def bin(x): ... return ''.join(x & (1 << i) and '1' or '0' for i in ... range(7,-1,-1)) ... >>> bin(12) '00

Re: howto print binary number

2008-05-07 Thread castironpi
On May 7, 3:31 pm, Mensanator <[EMAIL PROTECTED]> wrote: > On May 7, 3:13 pm, dmitrey <[EMAIL PROTECTED]> wrote: > > > hi all, > > could you inform how to print binary number? > > I.e. something like > > > print '%b' % my_number > > > it would be nice would it print exactly 8 binary digits (0-1, wi

Re: howto print binary number

2008-05-07 Thread Gary Herron
dmitrey wrote: hi all, could you inform how to print binary number? I.e. something like print '%b' % my_number it would be nice would it print exactly 8 binary digits (0-1, with possible start from 0) Thank you in advance, D -- http://mail.python.org/mailman/listinfo/python-list Python 3.0

Re: howto print binary number

2008-05-07 Thread Mensanator
On May 7, 3:13 pm, dmitrey <[EMAIL PROTECTED]> wrote: > hi all, > could you inform how to print binary number? > I.e. something like > > print '%b' % my_number > > it would be nice would it print exactly 8 binary digits (0-1, with > possible start from 0) > > Thank you in advance, D The gmpy works

howto print binary number

2008-05-07 Thread dmitrey
hi all, could you inform how to print binary number? I.e. something like print '%b' % my_number it would be nice would it print exactly 8 binary digits (0-1, with possible start from 0) Thank you in advance, D -- http://mail.python.org/mailman/listinfo/python-list