-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbits.py
64 lines (55 loc) · 1.24 KB
/
bits.py
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
58
59
60
61
62
63
64
def print_bits(item):
'''
Item: tuple of bytes and display time
This function is used to print out bits of a byte
'''
byte, time = item
s = ""
for b in byte:
comp = 0b00000001
for _ in range(8):
if(comp&b):
s += '1'
else:
s += '0'
comp = comp<<1
s += ' for '+ str(time) + ' '
print(s)
def flip_bits(byte, time):
'''
byte: an array of bytes
time: the display time
This function takes in an array of bytes and display time. It
flips the bits in each of the bytes (0b11110000 -> 0b00001111)
returns: a tuple with the array of bytes and the display time
'''
val = []
for b in byte:
val.append(~b)
return [val, time]
def phasor(time):
'''
time: the display time
This function moves a bit in a set number of bytes across the
bytes (0b00000001 -> 0b00000010 -> 0b00000100 -> etc...)
returns: an array of tuples that contain the byte arrays and
display times
'''
show = []
byte = 1
for _ in range(3):
show.append([[byte], time])
byte = byte<<1
for _ in range(3):
show.append([[byte], time])
byte = byte>>1
return show
if __name__ == '__main__':
b = [1, 70]
time = 2
print(print_bits([b,time]))
b = flip_bits(b,time)
print(print_bits(b))
b = phasor(time)
for thing in b:
print(print_bits(thing))