
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Explain JavaScript Bitwise NOT, Left shift and Right shift?
JavaScript Bitwise NOT
Example
<html> <body> <p id="not"></p> <script> document.getElementById("not").innerHTML = ~ 13; </script> </body> </html>
Output
-14
Explanation: It gives 0 for 1 and 1 for 0.The above result is 14.
JavaScript Bitwise leftshift operator
Example
<html> <body> <p id="left"></p> <script> document.getElementById("left").innerHTML = 5 << 2; </script> </body> </html>
Output
20
Explanation:Left side (<<) shift operator shifts the elements to left side filling the gap with 0's.In the above example 5 in binary form is given by 0101 so when shifted by 2 it gives 010100 Which in decimal given by 20.
JavaScript Bitwise Right operator
Example
<html> <body> <p id="right"></p> <script> document.getElementById("right").innerHTML = 5 >>> 2 ; </script> </body> </html>
Output
2
Explanation: Right shift operator(>>>) in contrast to left shift operator, shifts thebits to the right .In the above example 5 got moved and the result is 1.
- Related Articles
- Bitwise Right/ left shift numbers in Arduino
- What is JavaScript Bitwise Left Shift(
- What are Left Shift and Right Shift Operators (>> and
- What is JavaScript Bitwise Right Shift(>>) Operator?\n
- What is Bitwise Right Shift Operator (>>) in JavaScript?
- Left Shift and Right Shift Operators in C/C++
- What is Bitwise Left Shift Operator (
- Shift strings Circular left and right in JavaScript
- Bitwise right shift operators in C#
- Bitwise right shift operator in Java\n
- C# Bitwise and Bit Shift Operators
- What does the bitwise left shift operator do in Java?
- What does the bitwise right shift operator do in Java?
- What are the bitwise zero fill right shift zero operators in Java?
- What is unsigned Right Shift Operator (>>>) in JavaScript?

Advertisements