在 VBScript 中使用 AND 运算符计算两个数字之间的内容是什么?

What is calculated between two numbers using the AND operator in VBScript?

Option explicit
Dim VarA
Dim VarB
VarA = 2560 and 3
VarB = 2560 and 4
wscript.echo "VarA is "&VarA
wscript.echo "VarB is "&VarB

显示

VarA is 0
VarB is 0

有人请解释 VarAVarB 是如何产生 0.

它完全按照您的要求去做。

来自the documentation for the And Operator

If, and only if, both expressions evaluate to True, result is True. If either expression evaluates to False, result is False. The logical operation is not short-circuited. All expressions are evaluated.

在这种情况下,虽然作为 @MCND 再次来自文档:

The And operator also performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result.

因此 0 结果而不是显式布尔值。

但是,如果您想将这些值相加,则需要使用 Addition + Operator

Sums two numbers.

Option Explicit
Dim VarA
Dim VarB
VarA = 2560 + 3
VarB = 2560 + 4
WScript.Echo "VarA is " & VarA
WScript.Echo "VarB is " & VarB

输出:

VarA is 2563
VarB is 2564

有用的链接

  • (Number and Number) in VBscript
  • What is the difference between VBScript's + and & operator?