summaryrefslogtreecommitdiff
path: root/tools/binarize.py
blob: 6dcbdefa0ac3ff5bd17c58b44926bfcccc44fcd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# this is a simple script to convert the ascii files into binaries
# everything but 0 an 1 , or alternatively _ and X is ignored in 
# source file.

import binascii 
import sys


f=open(sys.argv[1],'r')
o=open(sys.argv[2],'wb')

print "binarizing " + sys.argv[1] + " to "+sys.argv[2] + "."

b=""
l=0

while True:

    c=f.read(1)

    if not c:
	break

    if c=="0" or c=='_':
	l+=1
	b+="0"

    if c=="1" or c=='X':
	l+=1
	b+="1"

    if l==8:
#	print b
	l=0
	o.write(chr(int(b,2)))
	b=""

o.close()