1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| -- coding: cp936 --
coging:UTF-8
二进制转16进制
ch=['0','1','2','3','4','5','6','7','8', '9','A','B','C','D','E','F'] x=int(input("请输入一个二进制数=")) y=0 k=0 while True: k+=1 i=x % 10 if i1: y=y+2**(k-1) x=x//10 if x0: break z='' while True: k=y % 16 z=ch[k]+z y=y // 16 if y==0: break print(z)
|