JavaScript 按位异或 (^) 运算符是什么?


如果两个位数不同,当使用按位或 (|) 运算符时,返回 1。

范例

你可以尝试运行下列代码来学习如何使用 JavaScript 按位异或运算符。

<!DOCTYPE html>
<html>
   <body>
      <script>
         document.write("Bitwise XOR Operator<br>");

         // 7 = 00000000000000000000000000000111
         // 1 = 00000000000000000000000000000001
         document.write(7 ^ 1);
      </script>
   </body>
</html>

更新于:20-May-2020

221 次阅读

开启你的 事业

完成课程,获得认证

开始
广告