I want to convert a string like this into an int: s = 'A0 00 00 00 63'. What’s the easiest/best way to do that?
For example '20 01' should become 8193 (2 * 16^3 + 1 * 16^0 = 8193).
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
int()with eitherstr.split():or
str.replace()and pass the base as 16:Here both
split()andreplace()are converting'20 01'into'2001':