Python Forum
Question about change hex string to integer sting in the list (python 2.7)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about change hex string to integer sting in the list (python 2.7)
#1
Hi all,

My attached short python 2.7 code in the attachment output a hex string in the list:
['0x74', '0x65', '0x73', '0x74']

I tried and have no idea how to change the output result from hex string to hex integer in the following like this for python 2.7 in the list:
[0x74, 0x65, 0x73, 0x74]

Thank you very much in advance.

Attached Files

.py   test.py (Size: 151 bytes / Downloads: 43)
Reply
#2
There is no "hex integer". There are just integers. When python displays an integer with the default string representation, it's as a decimal.

In other words, why do you want [0x74, 0x65, 0x73, 0x74] instead of [116, 101, 115, 116]? If it's to display, you can print it that way. Otherwise, it shouldn't matter.

>>> [ord(x) for x in "test"]
[116, 101, 115, 116]
>>> print("[" + ", ".join(hex(ord(x)) for x in "test") + "]")
[0x74, 0x65, 0x73, 0x74]
Gribouillis likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Feed List items with Integer euras 9 589 May-19-2021, 07:45 PM
Last Post: snippsat
  Question on HTML formatting with set string in message Cknutson575 3 628 Mar-09-2021, 08:11 AM
Last Post: Cknutson575
  LIST or ARRAY Comparison and change of value nio74maz 0 374 Dec-21-2020, 05:52 PM
Last Post: nio74maz
Question dict value, how to change type from int to list? swissjoker 3 685 Dec-09-2020, 09:50 AM
Last Post: perfringo
  How can I change a string. Mike Ru 3 873 Jun-03-2020, 10:55 AM
Last Post: buran
  question: finding multiple strings within string djf123 4 937 May-16-2020, 01:00 PM
Last Post: snippsat
  Change string into Dict Robin_at_Cantelli 2 1,583 Mar-05-2020, 10:37 AM
Last Post: vishalhule
  Python: possibilty ro make a list of the file in the folder & change the name of file go127a 0 569 Feb-05-2020, 01:16 PM
Last Post: go127a
  Why is this an error? (string and integer) pcsailor 4 1,666 Feb-05-2020, 08:26 AM
Last Post: DeaD_EyE
  List items verification for Integer type vintysaw 4 1,031 Jan-17-2020, 01:56 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

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