Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hex input
#1
Hi

I am looking to have user input 6 hex bytes that are then stored in a variable that I can then send out serial or IP socket, I am fine with the sending data to serial or IP socket, the bit I am struggling with is the entering the hex and storing as hex ????

Many Thanks
Reply
#2
You can enter and store the hex as a string.
Reply
#3
"hex" is normally just a form for input and output, not storage. For many network protocols you'll send octets in a specified order.

import sys
h = input("Input your hex data ")
try:
    d = int(h, 16)
except ValueError:
    print(f"{h} not a valid hex input")
    sys.exit()
print(f"The entered string {h} is {d} in decimal.")
# Validate d is in the correct range
# Send the data as necessary...
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020