Lesson 1 of 15

AND Gate

The AND Gate

A logic gate is a basic building block of digital circuits. The AND gate outputs 1 only when all inputs are 1. For any other combination, the output is 0.

ABA AND B
000
010
100
111

In JavaScript, the bitwise AND operator & performs this operation on individual bits:

1 & 1 // 1
1 & 0 // 0
0 & 1 // 0
0 & 0 // 0

Your Task

Implement and(a, b) that returns 1 if both inputs are 1, and 0 otherwise. Then print the output for all four input combinations.

JavaScript loading...
Loading...
Click "Run" to execute your code.