To convert a hex string to an integer

Asked 1 years ago, Updated 1 years ago, 108 views

in python script When the string stores hexadecimal digits How do I convert this string to int?

For example, str1 = "0xffff" str2 = "ffff" When we're together

string python hex

2022-09-21 18:01

1 Answers

In int(), you can specify the true value for the second factor.

str1 = "0xf"
str2 = "f"

print(int(("0xf", 0)) #prefix(0x) - automatically finds the type if the second factor is 0
print(int(("f", 16)) #If prefix does not exist - must be specified


2022-09-21 18:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.