summaryrefslogtreecommitdiffstats
path: root/test_20121121/hex2binary.py
diff options
context:
space:
mode:
Diffstat (limited to 'test_20121121/hex2binary.py')
-rwxr-xr-xtest_20121121/hex2binary.py31
1 files changed, 31 insertions, 0 deletions
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()