Python內置函數進制轉換的用法(十進制轉二進制、八進制、十六進制)html
1 def iptoint(num): 2 h=[] 3 s = num.split(".") 4 for temp in s: 5 a = bin(int(temp))[2:] 6 a = a.zfill(8) 7 h.append(a) 8 g = "".join(h) 9 e = int(g,2) 10 print e 11 12 iptoint('7.91.205.21')