/  Bin() method in Python Built in Function

Bin() method in Python Built in Function

 

bin method in built function returns the binary version of the number as the output.Only numbers are the values in this method.

 

Syntax

bin(x)

 

Parameters:

It has only single parameter

  • Num: it is an integer whose binary equivalent has to be calculated. The output will be executed with a prefix “0b”.

 

Example-1:

 

Using integer

x = bin(62)
print(x)

 

Output :

Bin() method in PythonBuilt in Function

 

Example-2:

 

Using negative value

x = bin(-98)
print(x)

 

Output:

Bin() method in PythonBuilt in Function

 

Example-3:

 

Using # symbol

x= format(18, '#b')
print (x)

 

Output:

Bin() method in PythonBuilt in Function

 

Example-4:

 

Using without # symbol

x= format(17, 'b')
print (x)

 

Output:

Bin() method in PythonBuilt in Function

 

Example-5:

 

Using  : and # symbols

x= f'{13:#b}'
print(x)

 

Output:

Bin() method in PythonBuilt in Function

 

Example-6:

 

Using without # symbol

x= f'{14:b}'
print (x)

 

Output:

Bin() method in PythonBuilt in Function