From f0fdd4b91cd4dded9e029a7a3a8b6a158d721a30 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 22 Nov 2012 00:21:11 +0100 Subject: add Nov 22nd notes and scripts --- test_20121121/hex2binary.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 test_20121121/hex2binary.py (limited to 'test_20121121/hex2binary.py') diff --git a/test_20121121/hex2binary.py b/test_20121121/hex2binary.py new file mode 100755 index 0000000..a4002da --- /dev/null +++ b/test_20121121/hex2binary.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import sys + +def main(fin, fout): + last = None + + for c in fin.read(): + if c not in "0123456789ABCDEF": + continue + if last == None: + last = c + continue + fout.write(chr(int("0x" + last + c, 16))) + last = None + + +if __name__=="__main__": + if len(sys.argv) == 1: + fin = sys.stdin + fout = sys.stdout + elif len(sys.argv) == 3: + fin = open(sys.argv[1], 'r') + fout = open(sys.argv[2], 'w') + print "working..." + else: + print "ERROR: wrong number of arguments (in_file + out_file OR none)" + + main(fin, fout) + fin.close() + fout.close() -- cgit v1.2.3