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)
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 (Size: 151 bytes / Downloads: 182)
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

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to change the datatype of list elements? mHosseinDS86 9 465 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  find some word in text list file and a bit change to them RolanRoll 3 421 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
Big Grin General programming question (input string)[ jamie_01 2 696 Jan-08-2022, 12:59 AM
Last Post: BashBedlam
  Change font in a list or tuple apffal 3 1,292 Oct-14-2021, 05:26 AM
Last Post: ndc85430
  Change a list to integer so I can use IF statement buckssg 3 1,329 Sep-21-2021, 02:58 AM
Last Post: bowlofred
  change csv file into adjency list ainisyarifaah 0 914 Sep-21-2021, 02:49 AM
Last Post: ainisyarifaah
  change string in MS word Mr_Blue 8 1,687 Sep-19-2021, 02:13 PM
Last Post: snippsat
  How to change odd to even numbers in the list? plumberpy 8 1,812 Aug-08-2021, 11:07 AM
Last Post: plumberpy
  Feed List items with Integer euras 9 2,452 May-19-2021, 07:45 PM
Last Post: snippsat
  Question on HTML formatting with set string in message Cknutson575 3 2,102 Mar-09-2021, 08:11 AM
Last Post: Cknutson575

Forum Jump:

User Panel Messages

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