Text to Binary Converter
This tool allows you to convert text into its binary representation.
Python Code
def text_to_binary(text):
return ' '.join(format(ord(char), '08b') for char in text)
# Example usage
input_text = "Hello, World!"
binary_output = text_to_binary(input_text)
print(f"Input: {input_text}")
print(f"Binary: {binary_output}")
Explanation
- The
text_to_binary()function converts each character in the input text to its binary representation. - We use
ord(char)to get the ASCII value of each character. - The
format()function with'08b'converts the ASCII value to an 8-bit binary string. - We join the binary representations with spaces for readability.
Interactive Converter
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!