From 083410edafe272c970c8760fc170eb09277c08b3 Mon Sep 17 00:00:00 2001 From: Luthics Date: Sat, 26 Nov 2022 11:43:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=AC=AC=E5=85=AD=E6=AC=A1?= =?UTF-8?q?=E5=AE=9E=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/6/1.py | 11 +++++++++++ test/6/2.py | 25 +++++++++++++++++++++++++ test/6/3.py | 8 ++++++++ 3 files changed, 44 insertions(+) create mode 100644 test/6/1.py create mode 100644 test/6/2.py create mode 100644 test/6/3.py diff --git a/test/6/1.py b/test/6/1.py new file mode 100644 index 0000000..c1e13fd --- /dev/null +++ b/test/6/1.py @@ -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)) diff --git a/test/6/2.py b/test/6/2.py new file mode 100644 index 0000000..27c101c --- /dev/null +++ b/test/6/2.py @@ -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) diff --git a/test/6/3.py b/test/6/3.py new file mode 100644 index 0000000..4a4db86 --- /dev/null +++ b/test/6/3.py @@ -0,0 +1,8 @@ +a, b = map(int, input().split()) +# if (a == b): +# print(0) +# else: +# print(1) +# 直接用上面的这个不就好了 +print((a & ~b) | (b & ~a)) +# 门电路模拟 \ No newline at end of file