Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How python Converts Integers into Binary Strings
How python Converts Integers into Binary Strings
Directly on the code:

# code =gbk

def? intTo2Str(? x? ,? k? ):

"""? intTo2Str(? x? ,? k? )

Can it be an integer? x? Become? K-bit binary string

"""

Try:

x? =? Dragon (? x)

Except:

x? =? 0

Try:

k? =? int(? k)

Except:

k? =? 0

What if? K & lt 1? :

k? =? 1?

What if? X & lt0? :

FH? =? 1? ; ? x? =? [Add to nouns in French etymology ending in -u to form plural]

Otherwise:

FH? =? 0?

Answer? =[? 0? For what? j? Are you online? xrange(? 0,? k? )? ]

j? =? K- 1

What time? (J & gt=0)? And then what? (? X & gt0):

y? =? x? %? 2

x? =? x? /? 2

A [? j? ]? =? Y

j? =? j? -? 1

What if? FH== 1:

#? supplement

For what? j? Are you online? xrange(? 0,? k):

What if? A[J]? == 1? :

A[J]? =? 0

Otherwise:

A[J]? =? 1

#? Add 1

j? =? k? -? 1

What time? J & gt=0:

A[J]? =? A[J]? + 1

What if? a[J]& lt; = 1:

Break;

A[J]? =? 0

j? =? j? - 1

Return? "".By adding ([? chr(J+48)? For what? j? Are you online? Answer? ])

Print? intTo2Str(? 8,? 8? )#? Should it be displayed? 0000 1000

Print? intTo2Str(? - 1,? 8? )#? Should it be displayed? 10000000