We can easily convert int in Python to binary string using the built-in bin() function.
Let's take a look at a few examples.
Example 1: decimal int to binary string
decimal_number = 42
binary_str = bin(decimal_number)
print(f"Binary of {decimal_number} = {binary_str}")
Output:
Example 2: hexadecimal int to binary string
hex_number = "FEFE"
binary_str = bin(int(hex_number, 16))
print(f"Binary of {hex_number}: {binary_str}")
Output:
Examples using Python interactive Shell

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!