Explain the bitwise AND (&) operator in JavaScript.
Explain the bitwise AND (&) operator in JavaScript.
216
30-Oct-2023
Updated on 31-Oct-2023
Aryan Kumar
31-Oct-2023The bitwise AND (&) operator in JavaScript is used to perform a bitwise AND operation on the individual bits of two numbers. It returns a new number where each bit is set to 1 only if the corresponding bits in both input numbers are 1.
Here's a simple explanation of how the bitwise AND operator works:
Here's an example:
In this example, the bitwise AND operation is applied to num1 and num2. The result has a 1 at the 2^0 position because it's the only position where both input numbers have a 1.
The bitwise AND operator is commonly used for tasks like isolating or testing specific bits within a number, setting certain bits to 0 in a binary representation, or performing bitwise operations in various programming scenarios.