---
title: "How does bitwise AND (&) work when applied to two binary numbers?"  
description: "How does bitwise AND (&) work when applied to two binary numbers?"  
author: "Steilla Mitchel"  
published: 2023-10-30  
updated: 2023-10-31  
canonical: https://www.mindstick.com/forum/160335/how-does-bitwise-and-work-when-applied-to-two-binary-numbers  
category: "javascript"  
tags: ["javascript", "bitwise operators"]  
reading_time: 1 minute  

---

# How does bitwise AND (&) work when applied to two binary numbers?

How does bitwise AND (&) work when applied to two [binary](https://www.mindstick.com/forum/34709/please-write-a-program-for-decimal-to-binary-conversion-in-c-sharp) numbers?

## Replies

### Reply by Aryan Kumar

The bitwise AND (&) operator in JavaScript is used to perform a bitwise AND operation on the individual bits of two binary numbers. It returns a new number where each bit is set (1) only if the corresponding bits in both input numbers are 1.

Let's take an example to understand how the bitwise AND operator works with binary numbers:

```plaintext
let num1 = 5; // Binary representation: 00000101
let num2 = 3; // Binary representation: 00000011

let result = num1 & num2; // Binary representation: 00000001

console.log(result); // Output: 1
```

In this example, the AND operation is performed on **num1** and **num2**. The result has a 1 at each position where both input numbers have a 1. So, **5 & 3** results in 1 because the only common bit set to 1 in both binary representations is the 2^0 position.

The bitwise AND operator is often used in programming to mask or isolate specific bits within a number, perform bit-level tests, or clear (set to 0) certain bits in a binary representation.


---

Original Source: https://www.mindstick.com/forum/160335/how-does-bitwise-and-work-when-applied-to-two-binary-numbers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
