Left Shift
The left shift operator is <<. The left shift operator shifts all bits in a number to the left by the number of positions.
2 (10 in binary) shifted 5 bits to the left is 64 (1000000 in binary).
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script type="text/javascript">
var oldValue = 2; //equal to binary 10
var newValue = oldValue << 5; //equal to binary 1000000 which is decimal 64
document.writeln(newValue);// 64
</script>
</head>
<body>
</body>
</html>
The left shift operator preserves the sign of the number. For instance, if -2 is shifted to the left by five spaces, it becomes -64, not positive 64.
Home
JavaScript Book
Language Basics
JavaScript Book
Language Basics
Operators:
- JavaScript Operators
- Increment/Decrement Operators
- Increment/Decrement Operators for String, Boolean, Floating-point and Object
- Unary Plus and Minus
- Bitwise Not operator
- Bitwise AND
- Bitwise OR
- Bitwise XOR
- Left Shift
- Signed Right Shift
- Unsigned Right Shift
- Logical NOT
- Logical AND
- Logical OR
- Multiply
- Divide
- Modulus
- Add
- Subtract
- Relational Operators
- Equal and Not Equal
- Identically Equal and Not Identically Equal
- Conditional Operator
- Assignment Operators
- Comma Operator