为XOR,NAND,NOR,XNOR逻辑编写代码 [英] write code for XOR, NAND, NOR, XNOR Logics
问题描述
我们可以通过简单的代码显示AND,OR的条件:
def funAnd():
如果condition1 和条件2:
返回True
#######
0 | 0 - > 0
0 | 1 - > 0
1 | 0 - > 0
1 | 1 - > 1
def funOr():
如果条件1 或条件2:
返回True
#######
0 | 0 - > 0
0 | 1 - > 1
1 | 0 - > 1
1 | 1 - > 1
######################################## br />
如何为XOR,NAND,NOR,XNOR逻辑生成条件测试。
########## XOR
0 | 0 - > 0
0 | 1 - > 1
1 | 0 - > 1
1 | 1 - > 1
########## NAND
0 | 0 - > 1
0 | 1 - > 1
1 | 0 - > 1
1 | 1 - > 0
########## NOR
0 | 0 - > 1
0 | 1 - > 0
1 | 0 - > 0
1 | 1 - > 0
########## XNOR
0 | 0 - > 1
0 | 1 - > 1
1 | 0 - > 1
1 | 1 - > 0
我们如何测试这些逻辑?
We can show conditions for AND, OR by simple codes:
def funAnd():
if condition1 and condition2:
return True
#######
0 | 0 -> 0
0 | 1 -> 0
1 | 0 -> 0
1 | 1 -> 1
def funOr():
if condition1 or condition2:
return True
#######
0 | 0 -> 0
0 | 1 -> 1
1 | 0 -> 1
1 | 1 -> 1
#######################################
what about generating conditional tests for XOR, NAND, NOR, XNOR logics.
########## XOR
0 | 0 -> 0
0 | 1 -> 1
1 | 0 -> 1
1 | 1 -> 1
########## NAND
0 | 0 -> 1
0 | 1 -> 1
1 | 0 -> 1
1 | 1 -> 0
########## NOR
0 | 0 -> 1
0 | 1 -> 0
1 | 0 -> 0
1 | 1 -> 0
########## XNOR
0 | 0 -> 1
0 | 1 -> 1
1 | 0 -> 1
1 | 1 -> 0
How can we test for these logic?
推荐答案
检查规则,例如到目前为止我记得NAND
仅仅是Not AND
。鉴于基础知识是大多数语言的一部分,编码规则应该相当简单。
Check the rules, for example as far as I recallNAND
is merelyNot AND
. Coding the rules should be fairly simple, given that the basics are part of most languages.
这篇关于为XOR,NAND,NOR,XNOR逻辑编写代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!