-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquiz_2_notes.txt
58 lines (34 loc) · 863 Bytes
/
quiz_2_notes.txt
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Encoding data using bits. Which is apparently an important technique.
Encoding example:
21 = 16 + 4 + 1
= 10101
->{0,2,4} or 2^0 + 2^2 + 2^4
6 =
5 =
= 101
{0,2}
If everything is seem is will be:
{0,1,2,3,4,5,6,7,8,9} which is 2^10-1
37
41 % 10 = 1
1 << 1 (push to the left once)
& should be zero of the two numbers
add the number with "or" ||
41 // 10 = 4
encode(23)
bin(831)
encode(23, 6)
106416
bin(106416)
0b110011111...
int('34') -> 34
int('10101', 2) -> 37 convert in bins to decimal
def encode(*integers)
return int('0'.join(''.join(c+C for c in bin(i)[2: ]) for i in integers), 2)
0 is the separator
bin(37[2: ] is the
print(c + c) join to numbers together eg. '11' or '00'
My number in base 2 with the first 2 characters separated
Task is to de-code the the encoding
-----------------------------------
scan the string and