Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python int binary

print('{0:b}'.format(3))        # '11'
print('{0:8b}'.format(3))       # '      11'
print('{0:08b}'.format(3))      # '00000011'

def int2bin(integer, digits):
    if integer >= 0:
        return bin(integer)[2:].zfill(digits)
    else:
        return bin(2**digits + integer)[2:]
print(int2bin(3, 6))            # '000011'
Comment

PREVIOUS NEXT
Code Example
Python :: Creating Python Sets 
Python :: pygame check collision 
Python :: switch between frames in tkinter 
Python :: for loop example python 3 
Python :: pandas filter on two columns 
Python :: pyton recognize any datetime format 
Python :: scikit tsne 
Python :: python plus 
Python :: python list files in directory 
Python :: python cls command line 
Python :: delete last few items from a list python 
Python :: chrome webdrivermanager 
Python :: comment out multiple lines in python 
Python :: python 2.7 get user input 
Python :: python merge list of dict into single dict 
Python :: int to hex python without 0x 
Python :: download unsplash images script 
Python :: how to change templates folder in flask 
Python :: odoo sorted 
Python :: beautifulsoup getting data from a website 
Python :: dataframe cut based on range 
Python :: python slicing 
Python :: how to make curl request python 
Python :: datetime.timedelta format to string python 
Python :: pickled list 
Python :: basic python programs 
Python :: sphinx autodoc command 
Python :: dataframe print column 
Python :: dict get value by index 
Python :: has no attribute python 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =