Last active
December 10, 2020 20:21
-
-
Save R4wm/99d43c9fd1c3a6be08590363e0d36e42 to your computer and use it in GitHub Desktop.
int an hex, hex to int
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/python3 | |
import re | |
import sys | |
import argparse | |
def getHex(a_user_int): | |
return hex(a_user_int).split('x')[-1].upper() | |
def getInt(a_hex): | |
return int(a_hex, 16) | |
if __name__ == '__main__': | |
l_parser = argparse.ArgumentParser() | |
l_parser.add_argument('hexorint', help="Enter either the int or hex for customer id") | |
l_args = l_parser.parse_args() | |
opts = (vars(l_args)) | |
if not re.match('[0-9|A-F|a-f]+$', opts['hexorint']): | |
print("Whachu talkin bout willis!?") | |
sys.exit(0) | |
try: | |
if int(opts['hexorint']): | |
print(getHex(int(opts['hexorint']))) | |
except ValueError: | |
print(getInt(opts['hexorint'])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment