Search code examples
pythonfunctionreturnhex

Function that returns a list of hexadecimal numbers (only hexadecimal digits)


I want to create a function that returns a list of hexadecimal digits only. But I don't know how to make it because when I tried to make it a hex function, hex returns as str. Does anyone know how to make this, can you make it and show it to me?

I've made numerous attempts and all have failed. and I want a function that can return a list that can be stored in a variable like below.

[0x18, 0x82, 0x19, 0x89, 0x91, 0x71, 0x38, 0x58, 0x10, 0x47, 0x89, 0x65, 0x86, 0x75, 0x26, 0x58,
 0x66, 0x44, 0x74, 0x72, 0x47, 0x11, 0x13, 0x30, 0x46, 0x13, 0x58, 0x28, 0x81, 0x55, 0x61, 0x23]

Solution

  • Why has no one advised this code?

    def make_key(text : str = None) :
        if text == None :
            raise ValueError("Untyped variable: 'text'")
        return [int(hex(ord(s)), 16) for s in text]