【发布时间】:2013-12-13 00:58:00
【问题描述】:
我一直在做一个 Python 项目,我正在尝试使用原始 ASCII 代码,并将其合并到密码中。但在此之前,我想知道是否有一种方法可以将 ascii 递归转换为二进制。 Python 2.7.5 顺便说一句。 这是我的代码:
inputMessage= raw_input("Enter message for conversion: ")
print "Decoded string: "
#text to ascii
for ch in inputMessage:
print ord(ch)
print "\n\n"
#ascii to binary
print "ASCII to Binary:"
print bin(ord(ch))
print
print "The Binary without the '0b':"
for ch in inputMessage:
print bin(ord(ch))[2::]
我在 shell 中的输出:
Enter message for conversion: Hi, my name is Johnny
Decoded string:
72
105
44
32
109
121
32
110
97
109
101
32
105
115
32
74
111
104
110
110
121
ASCII to Binary:
0b1001000
0b1101001
0b101100
0b100000
0b1101101
0b1111001
0b100000
0b1101110
0b1100001
0b1101101
0b1100101
0b100000
0b1101001
0b1110011
0b100000
0b1001010
0b1101111
0b1101000
0b1101110
0b1101110
0b1111001
我需要知道的是如何在转换为二进制时递归遍历 number 的 ascii 输出的每个数字。谁有解决办法?
【问题讨论】:
标签: python windows python-2.7