javascript中位运算的示例说明


摘要:
下文通过示例的方式javascript中运算的相关说明,如下所示;

位运算的功能:
js中位运算符用于数值转为二进制后进行相关运算,
左移指定位数,右移指定位数的操作,
下例将展示位运算的相关说明,如下所示:
例:

  <meta charset='utf-8' />
<p>
 maomao365.com<br />
 js位运算示例说明 
</p>
<hr />      
      <script>
         <!--
            var a = 8; //二进制 1000
            var b = 9; //二进制 1001
            var newLine = "<br />";
         
            document.write("(a & b) => ");
            result = (a & b);
            document.write(result);
            document.write(newLine);
         
            document.write("(a | b) => ");
            result = (a | b);
            document.write(result);
            document.write(newLine);
         
            document.write("(a ^ b) => ");
            result = (a ^ b);
            document.write(result);
            document.write(newLine);
         
            document.write("(~b) => ");
            result = (~b);
            document.write(result);
            document.write(newLine);
         
            document.write("(a << b) => ");
            result = (a << b);
            document.write(result);
            document.write(newLine);
         
            document.write("(a >> b) => ");
            result = (a >> b);
            document.write(result);
            document.write(newLine);
         //-->
      </script> 
javascript位运算示例说明

javascript位运算示例说明