Skip to content

Commit

Permalink
some python helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrh committed Sep 26, 2018
1 parent 707ad3c commit 4300b73
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions research/frombase2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys

result = []
cur_count = 0
cur_val = 0
for byte in sys.stdin.read():
if byte == '1':
cur_val |= (1<<cur_count)
elif byte != '0':
break
cur_count += 1
if cur_count == 8:
result.append(chr(cur_val))
cur_val = 0
cur_count = 0
if cur_count != 0:
result.append(chr(cur_val))
sys.stdout.write(''.join(result))
11 changes: 11 additions & 0 deletions research/tobase2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sys
result = []
def reverse(x):
return x[::-1]
ret = ''
for y in reversed(x):
ret += y
return ret
for byte in sys.stdin.read():
result.append(reverse("{0:#010b}".format(ord(byte)).replace("0b","")))
print ''.join(result)

0 comments on commit 4300b73

Please sign in to comment.