Skip to content

Introduction to Bitwise AND operator

Bitwise AND is the most commonly used logical Bitwise operator. It is represented by a sign (&). AND operator is the same as the AND gate we studied in the chapter on digital electronics.

ggorantala
ggorantala
1 min read

Table of Contents

Introduction

Bitwise AND is the most commonly used logical Bitwise operator. It is represented by a sign (&).

AND operator is the same as the AND gate we studied in the chapter on digital electronics, as shown below:

Sketch

AND gate
AND gate

What is the Bitwise AND operator?

The Bitwise AND operator is denoted by &. When an AND gate is given with two inputs, the corresponding output will be:

  • If two input bits are 1, the output is 1.
  • In all other cases, it's 0. For example
  • 1 & 0 => yields to 0.
  • 0 & 1 => yields to 0.
  • 0 & 0 => yields to 0.

Syntax

a & b

AND compares each bit of the first operand to the second operand’s corresponding bit. If both bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

Truth table

Bit ManipulationData Structures and Algorithms

ggorantala Twitter

Gopi has a decade of experience with a deep understanding of Java, Microservices, and React. He worked in India & Europe for startups, the EU government, and tech giants.

Comments


Related Posts

Members Public

Bit Manipulation Course Overview

Overview In this course, you will learn how to solve problems using bit manipulation, a powerful technique that can be used to optimize your algorithmic and problem-solving skills. This is one of the most important/critical topics when someone starts preparing for coding interviews for FAANG companies. To kick things

Members Public

Find Even Number Of Digits in an Array

This problem tests your knowledge of mathematics. Solving this problem helps you find the place values and how they are represented in the decimal number system.

Members Public

Array Strengths, Weaknesses, and Big-O Complexities

In this lesson, you will learn about array strengths and weaknesses along with the big-o complexities.