Advertisement
Guest User

Byte to bitstrings converter

a guest
Jun 8th, 2017
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. # Call with input and output files as arguments, for example:
  2. # $ bits.py res/GBK32.FON res/GKB32.processed
  3.  
  4. import sys
  5.  
  6.  
  7. def copyByte(input_, output):
  8.     byte = input_.read(1)
  9.     if len(byte) == 0:
  10.         return False
  11.     bits_str = '{0:08b}'.format(ord(byte)).replace('0', ' ').replace('1', '#')
  12.     bits = bits_str.encode('ascii')
  13.     output.write(bits)
  14.     return True
  15.  
  16.  
  17. with open(sys.argv[1], 'rb') as inf:
  18.     with open(sys.argv[2], 'wb') as outf:
  19.         while copyByte∞:
  20.             pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement