补充:
Python为我们提供了强大的内置函数和格式操作数字的方法去实现进制转换的功能
下载文件:
点击文本内容如下:
d87 x65 x6c x63 o157 d109 o145 b100000 d116 b1101111 o40 x6b b1100101 b1101100 o141 d105 x62 d101 b1101001 d46 o40 d71 x69 d118 x65 x20 b1111001 o157 b1110101 d32 o141 d32 d102 o154 x61 x67 b100000 o141 d115 b100000 b1100001 d32 x67 o151 x66 d116 b101110 b100000 d32 d102 d108 d97 o147 d123 x31 b1100101 b110100 d98 d102 b111000 d49 b1100001 d54 b110011 x39 o64 o144 o145 d53 x61 b1100010 b1100011 o60 d48 o65 b1100001 x63 b110110 d101 o63 b111001 d97 d51 o70 d55 b1100010 d125 x20 b101110 x20 b1001000 d97 d118 o145 x20 d97 o40 d103 d111 d111 x64 d32 o164 b1101001 x6d o145 x7e
我们发现有b、o、d、x这四种前缀,百度得:
八进制(逢八进一),Octal,缩写OCT或O,一类以8为基数的计数法,用O表示,为了不与数字0混淆,有时也用Q来表示八进制数。
十进制(逢十进一),英文为Decimal System,缩写Dec或D,来源于希腊文Decem,用D表示。
十六进制(逢十六进一),英文名称:Hexadecimal,是计算机里数据的一类表示方法。它由0-9,A-F组成,字母不区分大小写,前缀用0x表示。
二进制(逢二进一),Binary,用b表示。
即
D:十进制数Decima
B:二进制数Binary
0x(H):十六进制数Hexadecimal
O:八进制数Octal
因此,我们将这些统一转化为十六进制表示,然后转为字符串就可以得到答案。
编写进制转换代码脚本
#! /usr/bin/env python
#coding=utf-8
s=["d87","x65","x6c","x63","o157","d109","o145","b100000","d116","b1101111","o40","x6b","b1100101","b1101100","o141","d105","x62","d101","b1101001","d46","o40","d71","x69","d118","x65","x20","b1111001","o157","b1110101","d32","o141","d32","d102","o154","x61","x67","b100000","o141","d115","b100000","b1100001","d32","x67","o151","x66","d116","b101110","b100000","d32","d102","d108","d97","o147","d123",&