Created
October 30, 2021 16:19
-
-
Save daerich/5aa3cd4ec8c3cd74403870daa31df7c9 to your computer and use it in GitHub Desktop.
rough impl or base10 to any base calculation ignoring sign
This file contains 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
#!/usr/bin/env python | |
import sys | |
# Can't do 2 complement :C | |
res=None | |
quot=int(sys.argv[1]) | |
base=int(sys.argv[2]) | |
resstr="" | |
while quot != 0: | |
res = quot % base | |
quot = int(quot / base) | |
if base == 16: | |
match res: | |
case 10: | |
res = "A" | |
case 11: | |
res = "B" | |
case 12: | |
res = "C" | |
case 13: | |
res = "D" | |
case 14: | |
res = "E" | |
case 15: | |
res = "F" | |
resstr = str(res) + resstr | |
print(resstr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment