Programmin-in-Python

Converting Decimal IP Address to Hexadecimal equivalent

Jan 10th, 2021
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. ip = input("Enter the IP Address : ")
  2. L1 = ip.split(".")
  3. str1 = ""
  4.  
  5. for i in range(len(L1)):
  6.     int_i = int(L1[i])
  7.     hex_val = str(hex(int_i))
  8.     str1 += hex_val[2:].upper()
  9.     if i != len(L1) - 1:
  10.         str1 += "."
  11.  
  12. print("The IP Address in Hexadecimal : ", str1)
Advertisement
Add Comment
Please, Sign In to add comment