Skip to content

Commit 2ec8940

Browse files
Selective Set Operation
1 parent e59fe58 commit 2ec8940

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

selective_set_operation.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
def calclen(num1,num2):
2+
a = len(num1)
3+
b = len(num2)
4+
if a!=b :
5+
if a>b:
6+
for _ in range(a-b):
7+
num2='0'+num2
8+
else:
9+
for _ in range(b-a):
10+
num1='0'+num1
11+
return num1,num2
12+
13+
def selective_set(A,B):
14+
n=len(A)
15+
A = list(A)
16+
for i in range(n):
17+
if B[i]=='1':
18+
if A[i]=='0':
19+
A[i] = '1'
20+
21+
A="".join(A)
22+
return A
23+
24+
A = input("Enter bits of Register A : ")
25+
B = input("Enter bits of Register B : ")
26+
bin_A,bin_B = calclen(A,B)
27+
print("Selective Set Operation on A =",bin_A,"gives",selective_set(bin_A,bin_B))

0 commit comments

Comments
 (0)