Advertisement
Guest User

Untitled

a guest
Aug 16th, 2011
968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4.  
  5. hexchars = "0123456789abcdef"
  6. oldindex = None
  7.  
  8. while True:
  9.     x = sys.stdin.read(1)
  10.     if not x:
  11.         break
  12.  
  13.     x = x.lower()
  14.  
  15.     if x not in hexchars:
  16.         continue
  17.  
  18.     i = hexchars.index(x)
  19.  
  20.     if oldindex is None:
  21.         oldindex = i
  22.     else:
  23.         n = (oldindex << 4) | i
  24.         sys.stdout.write("%c" % n)
  25.         oldindex = None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement