icon

Convert Hex to Int in Python

Last modified: 2023-08-29

Conversion

We can convert hex to int by specifygin 16 in the second argument of the int method in Python.

int("7b", 16)
int("0x7b", 16)
# 123

int("68656c6c6f", 16)
int("0x68656c6c6f", 16)
# 448378203247

int("-80", 16)
int("-0x80", 16)
# -128