嗨,我的程序以这种方式打印:
消息转二进制:asd
01100001
01110011
01100100
但我需要像这样以水平形式打印消息(011000010111001101100100)
我一直在尝试我不知道该怎么做的一切。
def string_a_binario(s):
for i in range (0, len(s)):
if s[i] == " " :
print("00100001")
elif s[i] == "!" :
print("00100001")
elif s[i] == "#" :
print("00100011")
elif s[i] == "$" :
print("00100100")
elif s[i] == "%" :
print("00100101")
elif s[i] == "&" :
print("00100110")
elif s[i] == "'" :
print("00100111")
elif s[i] == "(" :
print("00101000")
elif s[i] == ")" :
print("00101001")
elif s[i] == "*" :
print("00101010")
elif s[i] == "+" :
print("00101011")
elif s[i] == "," :
print("00101100")
elif s[i] == "-" :
print("00101101")
elif s[i] == "." :
print("00101110")
elif s[i] == "/" :
print("00101111")
elif s[i] == "0" :
print("00110000")
elif s[i] == "1" :
print("00110001")
elif s[i] == "2" :
print("00110010")
elif s[i] == "3" :
print("00110011")
elif s[i] == "4" :
print("00110100")
elif s[i] == "5" :
print("00110101")
elif s[i] == "6" :
print("00110110")
elif s[i] == "7" :
print("00110111")
elif s[i] == "8" :
print("00111000")
elif s[i] == "9" :
print("00111001")
elif s[i] == ":" :
print("00111010")
elif s[i] == ";" :
print("00111011")
elif s[i] == "<" :
print("00111100")
elif s[i] == "=" :
print("00111101")
elif s[i] == ">" :
print("00111110")
elif s[i] == "?" :
print("00111111")
elif s[i] == "@" :
print("01000000")
elif s[i] == "A" :
print("01000001")
elif s[i] == "B" :
print("01000010")
elif s[i] == "C" :
print("01000011")
elif s[i] == "D" :
print("01000100")
elif s[i] == "E" :
print("01000101")
elif s[i] == "F" :
print("01000110")
elif s[i] == "G" :
print("01000111")
elif s[i] == "H" :
print("01001000")
elif s[i] == "I" :
print("01001001")
elif s[i] == "J" :
print("01001010")
elif s[i] == "K" :
print("01001011")
elif s[i] == "L" :
print("01001100")
elif s[i] == "M" :
print("01001101")
elif s[i] == "Ñ" :
print("01001110")
elif s[i] == "O" :
print("01001111")
elif s[i] == "P" :
print("01010000")
elif s[i] == "Q" :
print("01010001")
elif s[i] == "R" :
print("01010010")
elif s[i] == "O" :
print("01001111")
elif s[i] == "P" :
print("01010000")
elif s[i] == "Q" :
print("01010001")
elif s[i] == "R" :
print("01010010")
elif s[i] == "S" :
print("01010011")
elif s[i] == "T" :
print("01010100")
elif s[i] == "U" :
print("01010101")
elif s[i] == "V" :
print("01010110")
elif s[i] == "W" :
print("01010111")
elif s[i] == "X" :
print("01011000")
elif s[i] == "Y" :
print("01011001")
elif s[i] == "Z" :
print("01011010")
elif s[i] == "[" :
print("01011011")
elif s[i] == " \ " :
print("01011100")
elif s[i] == "]" :
print("01011101")
elif s[i] == "^" :
print("01011110")
elif s[i] == "_" :
print("01011111")
elif s[i] == "`" :
print("01100000")
elif s[i] == "a" :
print("01100001")
elif s[i] == "b" :
print("01100010")
elif s[i] == "c" :
print("01100011")
elif s[i] == "d" :
print("01100100")
elif s[i] == "e" :
print("01100101")
elif s[i] == "f" :
print("01100110")
elif s[i] == "g" :
print("01100111")
elif s[i] == "h" :
print("01101000")
elif s[i] == "i" :
print("01101001")
elif s[i] == "j" :
print("01101010")
elif s[i] == "k" :
print("01101011")
elif s[i] == "l" :
print("01101100")
elif s[i] == "m" :
print("01101101")
elif s[i] == "n" :
print("01101110")
elif s[i] == "o" :
print("01101111")
elif s[i] == "p" :
print("01110000")
elif s[i] == "q" :
print("01110001")
elif s[i] == "r" :
print("01110010")
elif s[i] == "s" :
print("01110011")
elif s[i] == "t" :
print("01110100")
elif s[i] == "u" :
print("01110101")
elif s[i] == "v" :
print("01110110")
elif s[i] == "w" :
print("01110111")
elif s[i] == "x" :
print("01111000")
elif s[i] == "y" :
print("01111001")
elif s[i] == "z" :
print("01111010")
elif s[i] == "{" :
print("01111011")
elif s[i] == "|" :
print("01111100")
elif s[i] == "}" :
print("01111101")
elif s[i] == "~" :
print("01111110")
s = list(input("Message to binary:"))
string_a_binario(s)