Skip to content

Instantly share code, notes, and snippets.

@daerich
Created October 30, 2021 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daerich/5aa3cd4ec8c3cd74403870daa31df7c9 to your computer and use it in GitHub Desktop.
Save daerich/5aa3cd4ec8c3cd74403870daa31df7c9 to your computer and use it in GitHub Desktop.
rough impl or base10 to any base calculation ignoring sign
#!/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