- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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
Bitwise operators are AND,OR,XOR.Let's discuss them individually.
a) AND operator
<html> <body> <p id="and"></p> <script> document.getElementById("and").innerHTML = 13 & 1; </script> </body> </html>
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
<html> <body> <p id="or"></p> <script> document.getElementById("or").innerHTML = 5 || 1; </script> </body> </html>
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
<html> <body> <p id="xor"></p> <script> document.getElementById("xor").innerHTML = 5 ^ 1; </script> </body> </html>
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.
- 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?
- How to use Java's bitwise operators in Kotlin?