#!usr/bin/env python
# Coding:utf-8
def binary ():
"Binary Method and algorithm"
Number = Ten
Number1 =
Number2 =
Print Bin (number), type (Bin (Number1)), Bin (Number2)
#用十进制算法来表示二进制
# except congruential: 10%2=0 put the string bit ' 0 ', 5%2=1 into the string 10 bits ' 10 ', 2%2=0 put in the Hundred ' 010 ', the last remainder into thousands ' 1010 '
L = []
While number>0:
L.insert (0,str (number%2)) #临时列表l每次从左插入计算后的余数
Number /= 2 #每次把Number除法的结果返回判断循环
Print L
s = '. Join (l) #列表转换字符串循环
Print S
def octonary ():
' octal methods and algorithms '
Number = Ten
Number1 =
Number2 =
Print Oct (number), Oct (Number1), Oct (Number2)
# except congruential: 10%8=2 put string bits ' 2 ', remainder into 10 bits '
L = []
While number>0:
L.insert (0,str (number%8))
Number /= 8
Print L
s = '. Join (L)
Print S
def hexadecimal ():
' hexadecimal method and algorithm '
Number =
Number1 =
Number2 =
Print Hex (number), Hex (Number1), Hex (Number2)
# except congruential: 30%16=14 because the single digit more than 10 put will not be recognized, so the letter instead of A=10,b=11,c=12,d==13,e=14,f=15
# Put the string bits ' e ', the remainder into 10 bits ' 1e '
L = []
While number>0:
n=str (number%16) #除余的数赋值变量n后面比对
L.insert (0,n)
Number /=
if n== ': l[0]= ' a ' #比对n是否为两位数10转换字符a
elif n== ' one ': l[0]= ' B ' #以下同理
elif n== ': l[0]= ' C '
elif n== ': l[0]= ' d '
elif n== ': l[0]= ' e '
elif n== ': l[0]= ' F '
Print L
s = '. Join (L)
Print S
If __name__== "__main__":
Binary ()
Octonary ()
Hexadecimal ()
Binary binary, octal, hex and its principle of Python