Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python binary representation of numbers

# get integer version of binary number
int(bin(8)[2:])
Comment

binary representation python

>>> bin(88)
'0b1011000'
>>> int('0b1011000', 2)
88
>>> 

>>> a=int('01100000', 2)
>>> b=int('00100110', 2)
>>> bin(a & b)
'0b100000'
>>> bin(a | b)
'0b1100110'
>>> bin(a ^ b)
'0b1000110'
Comment

generate binary number in python

num = int(input("Enter a number: ")) #generates a number
print(int(bin(num[2:]))) #converts the number to binary and prints it
#the [2:] is there because there is a b showing it is bnary but we dont want that in a binary number
Comment

PREVIOUS NEXT
Code Example
Python :: append extend python 
Python :: convert list to tuple python 
Python :: messagebox python pyqt 
Python :: csv len python 
Python :: max value indices 
Python :: python reading csv files from web 
Python :: hash table in python 
Python :: get ip address python 
Python :: pandas if else 
Python :: python seaborn color map 
Python :: python __str__ vs __repr__ 
Python :: python flask how to remove last character from string 
Python :: media pipe install ERROR: Could not find a version that satisfies the requirement mediapipe (from versions: none) 
Python :: how to check any script is running in background linux using python 
Python :: Matplotlib inside Jupyter | Jupyter generate graphs. 
Python :: write pyspark dataframe to csv 
Python :: change forms labels django 
Python :: sphere volume formula 
Python :: how to extract field values in list from queryset in django 
Python :: install python3.6 in linux 
Python :: while activating env show error of unautorize access in vscode 
Python :: inherit init method 
Python :: print input in python 
Python :: captions overlap in seaborn plot jupyter 
Python :: python pandas how to get the dataframe size 
Python :: parse int python 
Python :: how to reference variable in another file python 
Python :: parallel loops in python 
Python :: turn columns into one column as list python 
Python :: get key(s) for min value in dict python 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =