更新第六次实验

This commit is contained in:
Luthics 2022-11-26 11:43:40 +08:00
parent 533f9d9752
commit 083410edaf
3 changed files with 44 additions and 0 deletions

11
test/6/1.py Normal file
View File

@ -0,0 +1,11 @@
a = int(input())
b = int(input())
print("a的二进制", bin(a))
print("b的二进制", bin(b))
print("and", bin(a & b))
print("or", bin(a | b))
print("xor", bin(a ^ b))
print("a左移1位", bin(a << 1))
print("b左移1位", bin(b << 1))
print("a右移1位", bin(a >> 1))
print("b右移1位", bin(b >> 1))

25
test/6/2.py Normal file
View File

@ -0,0 +1,25 @@
a = input()
b = input()
# ands = ""
# ors = ""
xors = ""
while (len(a) > len(b)):
b = "0" + b
while (len(a) < len(b)):
a = "0" + a
for i in range(len(a)):
if (a[i] == "0" and b[i] == "0"):
# ands += "0"
# ors += "0"
xors += "0"
if ((a[i] == "1" and b[i] == "0") or (a[i] == "0" and b[i] == "1")):
# ands += "0"
# ors += "1"
xors += "1"
if (a[i] == "1" and b[i] == "1"):
# ands += "1"
# ors += "1"
xors += "0"
print(a)
print(b)
print(xors)

8
test/6/3.py Normal file
View File

@ -0,0 +1,8 @@
a, b = map(int, input().split())
# if (a == b):
# print(0)
# else:
# print(1)
# 直接用上面的这个不就好了
print((a & ~b) | (b & ~a))
# 门电路模拟