逻辑运算符优先级为 NAND、NOR、XNOR

发布于 2024-12-16 16:08:53 字数 525 浏览 0 评论 0原文

我在网上搜索过,但没有找到解决这个问题的方法。

运算符 NANDNORXNOR 的逻辑优先级是什么?

我的意思是,以表达式为例,

A AND B NAND C

应该首先评估哪个运算符?
显然 NAND 可以翻译为 NOT-AND (因为 NORNOT-ORXNOR< /code> 是 NOT-XOR),但是

(A AND B) NAND C != A AND (B NAND C) = A AND NOT(B AND C)

根据我的研究,这样的表达式没有定义的优先级,所以我认为最简单的解决方案是根据运算符在表达式中出现的顺序来计算它们表达,但我可能是错的。

有什么建议吗?

I've searched the web but I've found no solution to this problem.

What is the logical priority for operators NAND, NOR and XNOR?

I mean, considering as example the expression

A AND B NAND C

which operator should be evaluated first?
Obviously NAND can be translated as NOT-AND (as NOR is NOT-OR and XNOR is NOT-XOR), but

(A AND B) NAND C != A AND (B NAND C) = A AND NOT(B AND C)

According to my researches there's no a defined priority for such an expression, so I think the simplest solution is to evaluate the operators according to the order they appear in the expression, but I may be wrong.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

物价感观 2024-12-23 16:08:53

这实际上取决于您的优先规则。如果没有顺序(没有优先规则或所有内容都具有相同重要性),则应从左到右解决。 这里是一个 C++ 示例。

This actually depends on your precedence rules. If there is no order (no precedence rules or everything of the same importance), it should be solved left to right. Here is an example with C++.

最舍不得你 2024-12-23 16:08:53

运算符优先级必须由语言定义,而您这里所拥有的似乎不是正式语言,在这种情况下,通常假设您从左到右阅读时对其进行评估。

不过,您可以使用与 相同的运算符优先级verilog ,或查看 wikipedia其表优先级较小,常用于逻辑运算符

operator precedence have to be defined by a language, and what you have here doesn't seem to be a formal language, in such cases it's often assumed to be evaluated as you read from left to right.

Though, you could use the same operator precedence as verilog , or look at wikipedia which has a small table precedence commonly used for logic operators

桜花祭 2024-12-23 16:08:53

如果表达式的书写方式与问题中提到的方式相同(中间没有括号),则应按照它们的书写顺序进行求解。这是执行此操作的唯一正确方法。
例如。如果写成A NOR B XOR C,它的意思就是(A NOR B) XOR C

If the expression is written like the way it is mentioned in the question(without brackets in between), it should be solved in the order they are written. Thats the only correct way to do this.
eg. If its written line A NOR B XOR C, It simply means (A NOR B) XOR C

塔塔猫 2024-12-23 16:08:53

布尔运算符在传统算术中具有类似物,因此决定优先规则的一种方法是遵循传统算术的规则,例如 AND 类似于乘法,而 OR 类似于加法,因此 AND 的优先级应高于 OR。如果您查看 C 或 C++ 等语言的运算符优先级表,您会发现这些语言和其他相关语言中确实存在这种情况。

Boolean operators have analogues in conventional arithmetic, so one way of deciding what the precedence rules should be is to follow the rules for conventional arithmetic, e.g. AND is analogous to multiplication, while OR is analogous to addition, hence AND should have higher precedence than OR. If you look at the operator precedence table for a language such as C or C++ you will see that this is indeed the case in these and other related languages.

蹲在坟头点根烟 2024-12-23 16:08:53

我想这可能是特定于语言的,所有运算符都必须具有由特定实现定义或暗示的优先顺序。

这里是另一个网站对此的说法。

I suppose this could be language specific, ALL operators must have an order of precedence defined or implied by a specific implmentation.

Here is what another site has to say about that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文