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 148 views
2 answers 170 views
1 answer 128 views
128 views asked Sep 27, 2021 by avibootz
2 answers 263 views
1 answer 115 views
...