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: 245)
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
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 0 70 Yesterday, 01:16 PM
Last Post: ann23fr
  String to List question help James_Thomas 6 919 Sep-06-2023, 02:32 PM
Last Post: deanhystad
  Change font in a list or tuple apffal 4 2,632 Jun-16-2023, 02:55 AM
Last Post: schriftartenio
  syntax error question - string mgallotti 5 1,248 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  How to change the datatype of list elements? mHosseinDS86 9 1,896 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  find some word in text list file and a bit change to them RolanRoll 3 1,482 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
Big Grin General programming question (input string)[ jamie_01 2 1,568 Jan-08-2022, 12:59 AM
Last Post: BashBedlam
  Change a list to integer so I can use IF statement buckssg 3 2,194 Sep-21-2021, 02:58 AM
Last Post: bowlofred
  change csv file into adjency list ainisyarifaah 0 1,479 Sep-21-2021, 02:49 AM
Last Post: ainisyarifaah
  change string in MS word Mr_Blue 8 3,213 Sep-19-2021, 02:13 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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