Python十进制ip地址转二进制

时间:2025-04-01 15:37:46

自己写的,有用点个赞,谢谢啦☺️☺️

address = "110.123.12.503"

te = ()

ta = []

i = 1

j = 0

x = 0

tc = ''

answer = ''

te = (".")

while True:

    if bin(int(te[x]))[j:i:1] == "b":

        ta = bin(int(te[x]))[i::1]

        tc = ("0" * (8 - len(ta))) + ta

        x += 1

        i = 1

        j = 0

        answer = answer+tc

    i += 1

    j += 1

    if x == 4:

        break

print(answer)