source code of /small-scripts/ppt.py
| Last modified | |
| Lines | 52 |
Parent directory Download CGIread sitemap Main page
Quick links: count_holes main print_byte
#!/usr/bin/python
'''
Reads from stdin, writes to stdout.
- BEGIN
- | 7 6 5 4 | 3 2 1 0 |
7| - - | - |0
- END
'''
import sys
def count_holes(s):
holes = 0
for c in s:
x = ord(c)
for i in range(8):
if x & (1<<i):
holes += 1
return holes
def print_byte(c):
x = ord(c)
sys.stdout.write(' 7|')for i in range(7, -1, -1):
if i == 3:
sys.stdout.write(' | ')else:
sys.stdout.write(' ')if x & (1<<i):
sys.stdout.write('-')else:
sys.stdout.write(' ')sys.stdout.write(' |0\n')def main():
content = sys.stdin.read()
sys.stdout.write('- BEGIN BEGIN\n')sys.stdout.write('- | 7 6 5 4 | 3 2 1 0 | \n')for c in content:
print_byte(c)
sys.stdout.write('- END END\n')sys.stderr.write('{} Holes\n'.format(count_holes(content)))if __name__ == '__main__':
main()