Define and test a function to generate the binary sequence forthe input message. For example, if the input is “abc”, then thebinary sequence is 01100001 01100010 01100011 (97 98 99).(write thecode in python)
Answer
def dec_to_bin(x):
mystr=str(bin(x)[2:])
while(len(mystr)<8):
mystr=”0″+mystr
return mystr
text=input(“Input message: “)
for x in text:
print(dec_to_bin(ord(x)),end=” “)
main.py E Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux Input message: abc 01100001 01100010 01100011 1 def dec_to_bin(x): mystr-str(bin(x)[2:]) while(len(mystr)8) mystr-“o”+mystr return mystr 4 6 text-input(“Input message:”) 7 for x in text:
OR
OR