-1

So, I have a list containing strings that represent hex values like:

['02', 'ff', '98', '80', '39', '31', '03']

I would like to generate a new list that contains the actual hex values like:

[0x02, 0xff, 0x98, 0x80, 0x39, 0x31, 0x03]

Is there a way to do that?

If needed I can also get acces to the actual byte stream in the form of:

b'\x02\xff\x9c\x80D1\x03'

I need this "transformation" to perform bit-a-bit boolean operations on the elements of the list

7
  • 3
    What do you mean by 'actual hex values'? Hexadecimal is just a representation of an integer. Commented May 11, 2022 at 8:53
  • @LancelotduLac "actual hex" meaning a rapresentation of a byte into hex format as I will need to apply boolean operations to them. Maybe I explained myself not in the best way Commented May 11, 2022 at 9:02
  • @KellyBundy I'm not sure what you mean. Commented May 11, 2022 at 9:02
  • 1
    The values in your list and your "actual byte stream" don't seem to match. What's up with that? Commented May 11, 2022 at 9:03
  • 1
    @NicoCaldo the best way to be unambigous is to speak in terms of the type of object you want. Your question implies you want the int objects with the corresponding hexadecimal values Commented May 11, 2022 at 9:03

1 Answer 1

3

You can convert the hexadecimal string representations like this:

a = ['02', 'ff', '98', '80', '39', '31', '03']

b = [int(x, 16) for x in a]

This will create a list with integer equivalents of the input strings

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.