为XOR,NAND,NOR,XNOR逻辑编写代码 [英] write code for XOR, NAND, NOR, XNOR Logics

查看:412
本文介绍了为XOR,NAND,NOR,XNOR逻辑编写代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以通过简单的代码显示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 recall NAND is merely Not AND. Coding the rules should be fairly simple, given that the basics are part of most languages.


这篇关于为XOR,NAND,NOR,XNOR逻辑编写代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆