- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain about bitwise operators in JavaScript?
Bitwise operators are AND,OR,XOR.Let's discuss them individually.
a) AND operator
Example
<html> <body> <p id="and"></p> <script> document.getElementById("and").innerHTML = 13 & 1; </script> </body> </html>
Output
1
Explanation: Bitwise AND gives a value 1 when there are 2 ones in the same position.In the above example 13 in binary 1101 and 1 in binary 0001.So comparing both we have only one 1 common at the 1st position.So the value is 0001 that is 1.
b) OR operator
Example
<html> <body> <p id="or"></p> <script> document.getElementById("or").innerHTML = 5 || 1; </script> </body> </html>
Output
5
Explanation: Bitwise OR gives 1 when one of the digits is 1.In the above example the bitwise notation for 5 is 0101 and 1 is 0001 so the value will be 0101 that is 5.
c) XOR operator
Example
<html> <body> <p id="xor"></p> <script> document.getElementById("xor").innerHTML = 5 ^ 1; </script> </body> </html>
Output
4
Explanation: Bitwise XOR gives 1 when the bits are different if not it gives 0. In the above example 5 bitwise notation is 0101 and 1 is 0001. so the result is 0100 that is 4.
- Related Articles
- What are JavaScript Bitwise Operators?
- Bitwise Operators in C
- Bitwise Operators in C++
- Perl Bitwise Operators
- Java Bitwise Operators
- Python Bitwise Operators
- Bitwise operators in Dart Programming
- What are bitwise operators in C#?
- Bitwise right shift operators in C#
- What are the bitwise operators in Java?
- C# Bitwise and Bit Shift Operators
- What are different bitwise operators types in Python?
- Explain JavaScript Bitwise NOT, Left shift and Right shift?
- Explain in detail about memory leaks in JavaScript?
- How to use Java's bitwise operators in Kotlin?

Advertisements