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: 86)
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
  Change font in a list or tuple apffal 3 198 Oct-14-2021, 05:26 AM
Last Post: ndc85430
  Change a list to integer so I can use IF statement buckssg 3 275 Sep-21-2021, 02:58 AM
Last Post: bowlofred
  change csv file into adjency list ainisyarifaah 0 177 Sep-21-2021, 02:49 AM
Last Post: ainisyarifaah
  change string in MS word Mr_Blue 8 423 Sep-19-2021, 02:13 PM
Last Post: snippsat
  How to change odd to even numbers in the list? plumberpy 8 572 Aug-08-2021, 11:07 AM
Last Post: plumberpy
  Feed List items with Integer euras 9 1,052 May-19-2021, 07:45 PM
Last Post: snippsat
  Question on HTML formatting with set string in message Cknutson575 3 950 Mar-09-2021, 08:11 AM
Last Post: Cknutson575
  LIST or ARRAY Comparison and change of value nio74maz 0 573 Dec-21-2020, 05:52 PM
Last Post: nio74maz
Question dict value, how to change type from int to list? swissjoker 3 961 Dec-09-2020, 09:50 AM
Last Post: perfringo
  How can I change a string. Mike Ru 3 1,048 Jun-03-2020, 10:55 AM
Last Post: buran

Forum Jump:

User Panel Messages

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