Last active
September 13, 2019 12:43
-
-
Save artizirk/7d9344c6bb59b13de42868a0896356c2 to your computer and use it in GitHub Desktop.
k-space ascii task code for taltec/ttu orientation day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
c_per_line = 4 | |
text = """ | |
What you're referring to as Linux, is in fact, GNU/Linux, or as I've recently taken to calling it, GNU plus Linux. | |
""".strip().upper().replace(".", "").replace("\n", '') | |
print("64 32 16 8 4 2 1 "*c_per_line) | |
for word_nr, word in enumerate(text.split(" "), start=1): | |
# print word seperator line | |
print("{:_<{}}\n".format("Word nr: {}{}".format(str(word_nr), ' '+word if word_nr == 1 else ''), 24*c_per_line), end='') | |
# print word as binary | |
for i, c in enumerate(word): | |
# print character as binary | |
for b in "{:07b}".format(ord(c)): | |
print("{:2}".format(b), end=' ') | |
# make the first word a example by showing the characters | |
# after binary numbers | |
if word_nr == 1: | |
print(c, end='') | |
else: | |
print(' ', end='') | |
#print(c, end='') | |
# allow only c_per_line characters per line | |
if i!=0 and i% c_per_line == c_per_line-1: | |
print() | |
else: | |
# not end of line, print some spaces before next c | |
print(" ", end='') | |
# Words not dividable by c_per_line need a extra new line | |
if len(word) % c_per_line != 0: | |
print() | |
print("\n"*1) | |
print(""" | |
Example convertion | |
64 32 16 8 4 2 1 64 32 16 8 4 2 1 64 32 16 8 4 2 1 | |
1 0 0 1 0 0 0 1 0 0 0 1 0 1 1 0 0 1 1 0 0 | |
64+0 +0 +8+0 +0 +0=72=H 64+0 +0 +0 +4 +0 +1=69=E 64+0 +0 +8 +4 +0 +0=76=L | |
ASCII TABLE""") | |
for x in range(32, 128): | |
if x!=0 and x%8==0: | |
print() | |
print("{:>3} {}".format(x, chr(x)), end=' ') | |
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 32 16 8 4 2 1 64 32 16 8 4 2 1 64 32 16 8 4 2 1 64 32 16 8 4 2 1 | |
Word nr: 1 WHAT________________________________________________________________________________ | |
1 0 1 0 1 1 1 W 1 0 0 1 0 0 0 H 1 0 0 0 0 0 1 A 1 0 1 0 1 0 0 T | |
Word nr: 2______________________________________________________________________________________ | |
1 0 1 1 0 0 1 1 0 0 1 1 1 1 1 0 1 0 1 0 1 0 1 0 0 1 1 1 | |
1 0 1 0 0 1 0 1 0 0 0 1 0 1 | |
Word nr: 3______________________________________________________________________________________ | |
1 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 0 0 1 1 0 1 0 0 0 1 0 1 | |
1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 1 0 0 1 1 1 0 | |
1 0 0 0 1 1 1 | |
Word nr: 4______________________________________________________________________________________ | |
1 0 1 0 1 0 0 1 0 0 1 1 1 1 | |
Word nr: 5______________________________________________________________________________________ | |
1 0 0 0 0 0 1 1 0 1 0 0 1 1 | |
Word nr: 6______________________________________________________________________________________ | |
1 0 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 0 1 | |
1 0 1 1 0 0 0 0 1 0 1 1 0 0 | |
Word nr: 7______________________________________________________________________________________ | |
1 0 0 1 0 0 1 1 0 1 0 0 1 1 | |
Word nr: 8______________________________________________________________________________________ | |
1 0 0 1 0 0 1 1 0 0 1 1 1 0 | |
Word nr: 9______________________________________________________________________________________ | |
1 0 0 0 1 1 0 1 0 0 0 0 0 1 1 0 0 0 0 1 1 1 0 1 0 1 0 0 | |
0 1 0 1 1 0 0 | |
Word nr: 10_____________________________________________________________________________________ | |
1 0 0 0 1 1 1 1 0 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 1 | |
1 0 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 0 1 | |
1 0 1 1 0 0 0 0 1 0 1 1 0 0 | |
Word nr: 11_____________________________________________________________________________________ | |
1 0 0 1 1 1 1 1 0 1 0 0 1 0 | |
Word nr: 12_____________________________________________________________________________________ | |
1 0 0 0 0 0 1 1 0 1 0 0 1 1 | |
Word nr: 13_____________________________________________________________________________________ | |
1 0 0 1 0 0 1 0 1 0 0 1 1 1 1 0 1 0 1 1 0 1 0 0 0 1 0 1 | |
Word nr: 14_____________________________________________________________________________________ | |
1 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 0 0 0 1 1 1 0 0 0 1 0 1 | |
1 0 0 1 1 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 1 1 0 0 1 | |
Word nr: 15_____________________________________________________________________________________ | |
1 0 1 0 1 0 0 1 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 1 0 1 | |
1 0 0 1 1 1 0 | |
Word nr: 16_____________________________________________________________________________________ | |
1 0 1 0 1 0 0 1 0 0 1 1 1 1 | |
Word nr: 17_____________________________________________________________________________________ | |
1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 0 0 1 1 0 0 1 0 0 1 1 0 0 | |
1 0 0 1 0 0 1 1 0 0 1 1 1 0 1 0 0 0 1 1 1 | |
Word nr: 18_____________________________________________________________________________________ | |
1 0 0 1 0 0 1 1 0 1 0 1 0 0 0 1 0 1 1 0 0 | |
Word nr: 19_____________________________________________________________________________________ | |
1 0 0 0 1 1 1 1 0 0 1 1 1 0 1 0 1 0 1 0 1 | |
Word nr: 20_____________________________________________________________________________________ | |
1 0 1 0 0 0 0 1 0 0 1 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 1 1 | |
Word nr: 21_____________________________________________________________________________________ | |
1 0 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 1 1 1 0 1 0 1 0 1 0 1 | |
1 0 1 1 0 0 0 | |
Example convertion | |
64 32 16 8 4 2 1 64 32 16 8 4 2 1 64 32 16 8 4 2 1 | |
1 0 0 1 0 0 0 1 0 0 0 1 0 1 1 0 0 1 1 0 0 | |
64+0 +0 +8+0 +0 +0=72=H 64+0 +0 +0 +4 +0 +1=69=E 64+0 +0 +8 +4 +0 +0=76=L | |
ASCII TABLE | |
32 33 ! 34 " 35 # 36 $ 37 % 38 & 39 ' | |
40 ( 41 ) 42 * 43 + 44 , 45 - 46 . 47 / | |
48 0 49 1 50 2 51 3 52 4 53 5 54 6 55 7 | |
56 8 57 9 58 : 59 ; 60 < 61 = 62 > 63 ? | |
64 @ 65 A 66 B 67 C 68 D 69 E 70 F 71 G | |
72 H 73 I 74 J 75 K 76 L 77 M 78 N 79 O | |
80 P 81 Q 82 R 83 S 84 T 85 U 86 V 87 W | |
88 X 89 Y 90 Z 91 [ 92 \ 93 ] 94 ^ 95 _ | |
96 ` 97 a 98 b 99 c 100 d 101 e 102 f 103 g | |
104 h 105 i 106 j 107 k 108 l 109 m 110 n 111 o | |
112 p 113 q 114 r 115 s 116 t 117 u 118 v 119 w | |
120 x 121 y 122 z 123 { 124 | 125 } 126 ~ 127 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment