I'm trying to call a python script with a hexadecimal address, then add some offset to it:
import argparse
def main(number):
print(number+1234)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--input",type=int)
main(number=parser.parse_args().input)
Unfortunately, I have a type mismatch I can't seem to fix:
$ python hex.py --input=0x000000ab
usage: hex.py [-h] [--input INPUT]
hex.py: error: argument --input: invalid int value: '0x000000ab'
I must be missing some straightforward solution here.
This is a variation of the common FAQ "a string is not a number". You have to convert it, propably after skipping the 0x
prefix.
print(int(number.replace("0x", ""),16)+1234)
User contributions licensed under CC BY-SA 3.0