急急急!!!python关于ascii及进制转换问题单个字母或符号转化成二进制或十六进制数字!!!
下面是python的test...求帮助##TestsforConverterTest1-uppercasecharacter>bin>>>converter('A','...
下面是python的test...求帮助
## Tests for Converter
Test 1 - upper case character > bin
>>> converter('A', 'bin')
Bin: 01000001
Test 2 - lower case character > bin
>>> converter('a', 'bin')
Bin: 01100001
Test 3 - number > bin
>>> converter('2', 'bin')
Bin: 00110010
Test 4 - special character > bin
>>> converter('$', 'bin')
Bin: 00100100
Test 5 - special character > bin
>>> converter('%', 'bin')
Bin: 00100101
Test 6 - upper case character > hex
>>> converter('A', 'hex')
Hex: 41
Test 7 - lower case character > hex
>>> converter('j', 'hex')
Hex: 6A
Test 8 - number > hex
>>> converter('2', 'hex')
Hex: 32
Test 9 - special character > hex
>>> converter('|', 'hex')
Hex: 7C
Test 10 - special character > hex
>>> converter('?', 'hex')
Hex: 3F
坐等各位大神了,好的话还可以加分 展开
## Tests for Converter
Test 1 - upper case character > bin
>>> converter('A', 'bin')
Bin: 01000001
Test 2 - lower case character > bin
>>> converter('a', 'bin')
Bin: 01100001
Test 3 - number > bin
>>> converter('2', 'bin')
Bin: 00110010
Test 4 - special character > bin
>>> converter('$', 'bin')
Bin: 00100100
Test 5 - special character > bin
>>> converter('%', 'bin')
Bin: 00100101
Test 6 - upper case character > hex
>>> converter('A', 'hex')
Hex: 41
Test 7 - lower case character > hex
>>> converter('j', 'hex')
Hex: 6A
Test 8 - number > hex
>>> converter('2', 'hex')
Hex: 32
Test 9 - special character > hex
>>> converter('|', 'hex')
Hex: 7C
Test 10 - special character > hex
>>> converter('?', 'hex')
Hex: 3F
坐等各位大神了,好的话还可以加分 展开
1个回答
展开全部
def converter(char, base):
bases = {'hex': hex, 'bin': bin, 'dec': str, 'oct': oct}
print('%s: %s' % (base.title(), bases[base](ord(char))[2:]))
converter('A', 'hex')
参数名 char base 替换成 character number_system 不会有影响,这只是个参数名。
bases = {'hex': hex, 'bin': bin, 'dec': str, 'oct': oct}
print('%s: %s' % (base.title(), bases[base](ord(char))[2:]))
converter('A', 'hex')
参数名 char base 替换成 character number_system 不会有影响,这只是个参数名。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询