-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitbybit.py
68 lines (56 loc) · 1.85 KB
/
bitbybit.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
65
66
67
68
# bitbybit
# Author: Debbie Macrohon
# Description: Using various if-else statements and hardcoded commands
# for pseudo bit-manipulation using an array.
def main():
over = False
loop(over)
def loop(over):
while not over:
rounds = int(input())
array = ["?"]*32
if rounds ==0:
over = True
loop(over)
break
for i in range(0, rounds):
inp = input().split()
command = inp[0]
resultBit = int(inp[1])
if command=="SET":
array[resultBit] = "1"
elif command =="CLEAR":
array[resultBit] = "0"
elif command == "OR":
bitCommanded = int(inp[2])
if array[resultBit] == "1" or array[bitCommanded]=="1":
array[resultBit] = "1"
elif array[resultBit] == "0" and array[bitCommanded]=="0":
array[resultBit] = "0"
elif array[resultBit] == "0" and array[bitCommanded]=="?":
array[resultBit] = "?"
elif array[resultBit] == "?" and array[bitCommanded]=="0":
array[resultBit] = "?"
elif array[resultBit] == "?" and array[bitCommanded]=="?":
array[resultBit] = "?"
elif command == "AND":
bitCommanded = int(inp[2])
#print("arrayBitComm {}".format(array[bitCommanded]))
if array[resultBit] == "1" and array[bitCommanded]=="1":
array[resultBit] = "1"
elif array[resultBit] == "1" and array[bitCommanded]=="0":
array[resultBit] = "0"
elif array[resultBit] == "0" and array[bitCommanded]=="1":
array[resultBit] = "0"
elif array[resultBit] == "0" and array[bitCommanded]=="0":
array[resultBit] = "0"
elif array[resultBit] == "?" and array[bitCommanded]=="0":
array[resultBit] = "0"
elif array[resultBit] == "0" and array[bitCommanded]=="?":
array[resultBit] = "0"
elif array[resultBit] == "?" or array[bitCommanded]=="?":
array[resultBit] = "?"
for i in range(31,-1,-1):
print(array[i], end='')
print()
main()