diff --git a/Python/String_to_binary.py b/Python/String_to_binary.py new file mode 100644 index 00000000..0d218bda --- /dev/null +++ b/Python/String_to_binary.py @@ -0,0 +1,16 @@ + +# Converting String to binary +# Using join() + ord() + format() + +# initializing string +test_str = "Ashutosh" + +# printing original string +print("The original string is : " + str(test_str)) + +# using join() + ord() + format() +# Converting String to binary +res = ''.join(format(ord(i), '08b') for i in test_str) + +# printing result +print("The string after binary conversion : " + str(res))