-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbitwise.py
47 lines (39 loc) · 1.2 KB
/
bitwise.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
def bitwise_converter(line):
word_list=line.split()
index=0
new_list=[]
while(index <(len(word_list))):
word=word_list[index]
if(index<len(word_list)-1 and word=='bitwise'):
index+=1
word=word_list[index]
if(word=='and'):
new_list.append("&")
index+=1
continue
elif(word=="or"):
new_list.append("|")
index+=1
continue
elif(word=='xor'):
new_list.append('^')
index+=1
continue
elif(word=='not'):
new_list.append("~")
index+=1
continue
elif(word=="right"):
new_list.append(">>")
index+=1
continue
elif(word=="left"):
new_list.append("<<")
index+=1
continue
else:
new_list.append(word)
index+=1
new_line=" ".join(new_list)
return(new_line)
#print(bitwise_converter("a bitwise and b bitwise or c bitwise right d"))