How to display the bits of an integer in Python

3 Answers

0 votes
n = 13

print("{0:b}".format(n))




'''
run:

1101

'''

 



answered Sep 27, 2021 by avibootz
0 votes
n = 13

print(bin(n))




'''
run:

0b1101

'''

 



answered Sep 27, 2021 by avibootz
0 votes
n = 12 # 1100 
  
print(bin(n)[2:])
  
n = 386 # 1 1000 0010
  
print(bin(n)[2:])

 
 
'''
run:
  
1100
110000010
  
'''

 



answered Dec 5, 2021 by avibootz

Related questions

2 answers 255 views
2 answers 268 views
1 answer 208 views
208 views asked Sep 27, 2021 by avibootz
2 answers 390 views
1 answer 198 views
...