The bin() function in Python is a built-in function used to convert an integer number into its binary representation. The binary number is returned as a string prefixed with 0b, which indicates that the number is in base-2 (binary system).
Binary numbers are widely used in computer systems and digital electronics, where numbers are represented using only two digits: 0 and 1.
bin(number)
0b, which indicates binary format.print(bin(10))
Output
0b1010
Explanation
0b to indicate binary format.print(bin(7))
Output
0b111
Explanation
0b PrefixSometimes we may want only the binary digits without the prefix.
num = 10
binary = bin(num)
print(binary[2:])
Output
1010
Explanation
binary[2:] removes the first two characters (0b) from the string.print(bin(-8))
Output
-0b1000
Explanation
number = 25
binary_value = bin(number)
print("Decimal:", number)
print("Binary:", binary_value)
Output
Decimal: 25
Binary: 0b11001
Explanation
bin() is a built-in Python function used to convert an integer into its binary representation.0b prefix, indicating binary format.