Forth 中的逻辑与?

发布于 2024-09-26 04:30:09 字数 71 浏览 1 评论 0原文

我知道 AND 词定义了二进制 and...但是什么定义了逻辑 and 呢?

I know the AND word defines binary and... but what defines logical and?

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

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

发布评论

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

评论(2

征﹌骨岁月お 2024-10-03 04:30:09

相同单词AND也用于逻辑。但AND的两个输入值建议采用格式良好的标志truefalse 由两个值表示,全部设置的位 (-1) 和全部未设置的位 (0)。除这些值之外的其他值也可以正常工作(如 C 中),但可能会导致细微的错误。

所有比较运算符都会返回格式良好的标志,但例如 - 则不会。以下计算结果为 false (0)。

7 5 - 7 3 - AND

AND 获取位模式 100 和 010。结果为 0(因为它按位 and 进行运算)。

参考文献:

  1. Forth 中的位操作学习 Forth Bit 的一部分位
  2. 《Starting》第 4 章中的“一点逻辑”部分第四。。

The same word, AND, is also used for logical and. But the two input values to AND are recommended to be well-formed flags; true and false are represented by two values, bits all set (-1) and bits all unset (0). Other values than these may work as true (as in C), but it may lead to subtle errors.

All comparison operators return well-formed flags, but for instance - does not. The following evaluates to false (0).

7 5 - 7 3 - AND

AND gets bit patterns 100 and 010. The result is 0 (as it does the bitwise and).

References:

  1. Bit Manipulations in Forth, part of Learning Forth Bit by Bit.
  2. Section "A Little Logic" in Chapter 4 of Starting Forth.
昔梦 2024-10-03 04:30:09

第四个 AND 是对 64 位值进行按位 AND。当然,这些操作员戴着口罩工作得很好。但如果这些值全为 1 或全 0,则结​​果也为全 1 或全 0(按位 OR 和 XOR INVERT 运算也是如此)。

Forth 中的布尔标志是全 1 或全 0。因此,如果输入是布尔标志,则 AND OR XOR INVERT 的输出也是布尔值,因此这些运算符可用于表示布尔运算符。请注意 = < 之类的操作0= 产生布尔标志。

情况与+相同。由于整数被定义为二补码,因此 +(加号)可用于有符号数和无符号数。因此,无符号整数加法没有单独的名称。

The Forth AND is a bit-wise AND on 64 bit values. Of course these operators work okay with masks. But if these values are all ones or all zeroes, the result is also all ones or all zeroes (the same is true for bit-wise OR and XOR INVERT operations.).

A boolean flag in Forth is all ones or all zeroes. So if the inputs are boolean flags, the output of AND OR XOR INVERT are also booleans and those operators can thus be used to represent boolean operators. Please note that operations like = < 0= result in a boolean flag.

The situation is the same with +. Because integers are defined as two-complement, + (plus) can be used for signed as well as unsigned numbers. So there is no separate name for unsigned addition of integers.

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