Garronde
Garronde

Reputation: 53

Python converting a hexString

Working with NFC with pyscard I received a hexstring like this "01 CB"

I need to convert it to something like that b'\x01\xCB'

--

I know it is a 2 octet big endian and should be equal to 459.

I basically want to run that after the conversion int.from_bytes(b'\x01\xCB', byteorder='big')

Any help is appreciated, thanks

Upvotes: 0

Views: 49

Answers (1)

Daweo
Daweo

Reputation: 36725

If you need just integer value you might simply remove space and treat it just like hex-number i.e.:

string = "01 CB"
digits = string.replace(" ","")
value = int(digits,16)
print(value)

Output:

459

int's second (optional) argument is base - this can be any number from 2 to 36.

Upvotes: 1

Related Questions