CodesJava

Easy learning with example program codes

javascript bitwise operators tutorial

JavaScript Bitwise Operators:

JavaScript bitwise operators are used to perform bitwise operations on the operands

JavaScript Bitwise Operators List:

OperatorDescriptionExample
&Bitwise AND(10==25 & 20==35) = false
|Bitwise OR(20==30 | 20==40) = false
^Bitwise XOR(20==30 ^ 30==40) = false
~Bitwise NOT(~20) = -20
<<Bitwise Left Shift(10<<2) = 40
>>Bitwise Right Shift(10>>2) = 2
>>>Bitwise Right Shift with Zero(10>>>2) = 2

JavaScript Bitwise Operators Example:

<html>
<head>
<script type="text/javascript">
            var a = 2; 
            var b = 3; 
            var linebreak = "<br />";
 
            document.write("(a & b) => ");
            result = (a & b);
            document.write(result);
            document.write(linebreak);
 
            document.write("(a | b) => ");
            result = (a | b);
            document.write(result);
            document.write(linebreak);
 
            document.write("(a ^ b) => ");
            result = (a ^ b);
            document.write(result);
            document.write(linebreak);
 
            document.write("(~b) => ");
            result = (~b);
            document.write(result);
            document.write(linebreak);
 
            document.write("(a << b) => ");
            result = (a << b);
            document.write(result);
            document.write(linebreak);
 
            document.write("(a >> b) => ");
            result = (a >> b);
            document.write(result);
            document.write(linebreak);
      </script>
</head>
   <body>
   </body>
</html>

Try it:

JS Bin on jsbin.com

Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status