简体   繁体   English

Windows批处理脚本中的SET / A命令中使用的&符号

[英]ampersand used in SET /A command in Windows batch script

Could you please advice what using "&" or "^" in SET command means (I haven't found any explanation by using Google). 您能否建议SET命令中使用“&”或“ ^”的含义是什么(我使用Google找不到任何解释)。

For example, following Windows batch code block 例如,以下Windows批处理代码块

SET V_COMMAND=3
SET /A V_FLAG="%V_COMMAND%&2"
echo VFlag is: %V_FLAG%

produces: 生产:

VFlag is: 2

But I haven't any opinion about what command above does. 但是我对上面的命令没有任何意见。

Also there is another case with " ^ ": 另外还有一个带有“ ^ ”的情况:

SET V_COMMAND=3
SET /A V_FLAG="%V_COMMAND%^3"
echo VFlag is: %V_FLAG%

For this case output is: 对于这种情况,输出为:

VFlag is: 0

Since you are using set /a , the indicated characters are bitwise operators: 由于您使用的是set /a ,因此指示的字符是按位运算符:

& = bitwise AND = 1 if both bits are 1
^ = bitwise XOR = 1 if only one of the two bits is 1

So if a is 10 ( 1010 in binary) and b is 13 ( 1101 in binary) 因此,如果a10 (二进制为1010 )而b为13(二进制为1101

         1010              1010
         1101              1101
         ----              ----
         1000 = a & b      0111 = a ^ b

Or in your case with 3 dec = 11 bin and 2 dec = 10 bin 或者您的情况是3 dec = 11 bin2 dec = 10 bin

           11                11
           10                11
           --                --
           10 = 3&2 = 2      00 = 3^3 = 0

Those are bitwise operators - & is bitwise AND, and ^ is bitwise XOR. 这些是按位运算符- &是按位AND, ^是按位XOR。 These bitwise operators are only available with SET /A . 这些按位运算符仅可用于SET /A

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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