#!/usr/bin/python
#
# $Id: ascii2bin.py,v 1.2 2006/02/28 20:31:03 jlivesey Exp $
#
# This takes an ascii string in the range [0-9a-f]* from
# the command line and outputs the binary of it interpreted
# as ascii characters.
#
# % ./ascii2bin.py 0123456789 > foo
# % od -x foo
#   0000000 2301 6745 0089
#   0000005
#
#

#
# System library
#
import sys

#
# Get an ascii string from the command line
#
str = sys.argv[1]

#
# Take characters in pairs over the range of the input string. 
#
# str[x:x+2] is the slice of str from str[x] to str[x+1].
# int(str[x:x+2], 16) is that slice interpreted as hex.
#
for x in range(0, len(str), 2):
    sys.stdout.write(chr(int(str[x:x+2], 16)))

# eof
