ip = '192.168.12.87' lst = ip.split('.') for i in range(len(lst)): s = bin(int(lst[i])) print(s) # 0b11000000 0b10101000 0b1100 0b1010111 lst[i] = s[2:] print(lst) if len(lst[i]) < 8: s1 = '0'*(8-len(lst[i])) + lst[i] lst[i] = s1 val = ''.join(lst) print(val) print(int('0b' + val,base=2))