How do I convert a hex string to an integer?
"0xffff" ⟶ 65535 "ffff" ⟶ 65535
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.
Without the
0xprefix, you need to specify the base explicitly, otherwise there’s no way to tell:With the
0xprefix, Python can distinguish hex and decimal automatically:(You must specify
0as the base in order to invoke this prefix-guessing behavior; if you omit the second parameter,int()will assume base-10.)