简体   繁体   中英

Logical AND in Forth?

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

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM