2022年4月12日 星期二

python 二進位、format、rjust

 ip = '210.70.45.3'

ip = ip.split('.')

ip1 = []

for i in ip:

    ip1.append(format(int(i),'b').rjust(8,'0'))

ip1 = '.'.join(ip1)

print(ip1)

沒有留言:

張貼留言