Created
September 18, 2014 18:00
-
-
Save mazurov/fd04d5318efd44ed7909 to your computer and use it in GitHub Desktop.
5.7 Base conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 5.7 Base conversion | |
| def base10(s, b): | |
| res = 0; | |
| for c in s: | |
| res = res * b + (ord(c)-ord('0') if ord(c) <= ord('9') else 10 + ord(c) - ord('A')) | |
| return res | |
| x = base10('AA',16) | |
| print(x) | |
| x = base10('111',2) | |
| print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment