①输入的字符为十六进制数(英文字母大写,确保输入的个数为3的倍数),如4AC
②字符串中的每个字符转成四位二进制,按序拼接,如010010101100
③二进制字符串每4位进行前后倒置(即4位数左右倒置)操作,如001001010011
④将倒置后的字符串每3位转换成1位十进制,按序拼接后输出该十进制串,如001001010011转为1123
根据该规则编写的程序如下,运行结果如图所示,请回答以下问题:
Hex={"0":"0000","1":"0001","2":"0010","3":"0011","4":"0100","5":"0101","6":"0110","7":"0111","8":"1000","9":"1001","A":"1010","B":"1011","C":"1100","D":"1101","E":"1110","F":"1111"}
sch=input("请输入一个十六进制数(字母大写):")
th=""
for k in sch:
if "0"<=k<="9" or "A"<=k<="F": #若k为数字字符或大写字母
① #每1位十六进制转成4位二进制
ts=""
for i in range(0, ② ): #每4位进行前后倒置
ts+=th[i+3]+th[i+2]+th[i+1]+th[i]
tob=""
tmp=0
for i in range(len(ts)): #二进制串转十进制
tmp=tmp*2+int(ts[i]) #累乘相加转换成十进制
if #每3个字符为一组进行转换后的拼接
tob=tob+str(tmp)
tmp=0
print("变换后的字符串为:",tob)
① ②