Reputation: 31
How do I get the A to F hex numerals in as user input via something like:
hexnum=raw_input("input your hex number -> ")
Then I have a problem with such input not being convertible via:
number=int(hexnum)
I am looking for a simple example with a basic explanation.
Upvotes: 2
Views: 12325
Reputation: 385600
The int
constructor takes a base as its optional second argument.
>>> int('12AF', 16)
4783
Upvotes: 5
Reputation: 226296
This should work fine. Just inform int that it is working with base 16: int(hexnum, 16)
.
>>> hexnum = raw_input("input your hex number -> ")
input your hex number -> 2F
>>> print int(hexnum, 16)
47
Upvotes: 4