Re: Convert integer to fixed length binary string

Discussion in 'Python' started by Mark Dickinson, Jun 11, 2009.

  1. 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, 14:57:27)
    [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> '{0:032b}'.format(12345)

    '00000000000000000011000000111001'

    Mark
    Mark Dickinson, Jun 11, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sam
    Replies:
    3
    Views:
    14,095
    Karl Seguin
    Feb 17, 2005
  2. Aquila Deus
    Replies:
    3
    Views:
    2,065
    Aquila Deus
    Jul 24, 2004
  3. Ulrich Eckhardt
    Replies:
    1
    Views:
    885
    casebash
    Jun 12, 2009
  4. Victor Bazarov
    Replies:
    2
    Views:
    702
    Alf P. Steinbach
    May 3, 2010
  5. cpp4ever
    Replies:
    2
    Views:
    888
    cpp4ever
    May 4, 2010
Loading...

Share This Page