BusAND

Inputs

PinTypeDescription
Abus8First input bus (8 bits)
Bbus8Second input bus — mask (8 bits)

Outputs

PinTypeDescription
Qbus8Bitwise AND: A & B

How It Works

Picture two buses as two rows of eight switches lined up facing each other. BusAND compares the rows position by position: a 1 appears on the output only where both bus A and bus B carry a 1. A single 0 in the pair — and that output position goes to zero. That is why the second bus is usually called a mask: it decides which bits pass through and which get blocked.

The key property is masking. Where the mask bit is 1, the bit from A passes to the output unchanged; where it is 0, the bit turns to zero. A byte example: 10110110 AND 00001111 = 00000110 — the mask 00001111 "carved out" the low nibble and wiped the high bits. The opposite situation: 11110000 AND 00001111 = 00000000 — the masks do not overlap, so the result is empty.

A subtlety: AND never creates new ones — the result has no more ones than either input. This gives two extreme cases: A AND 11111111 = A (a "transparent glass" mask) and A AND 00000000 = 0 (complete zeroing). Engineers use the second case deliberately — more on that below.

8-bit Examples

A (bin)B (bin)Q (bin)Q (dec)
1111000000001111000000000
1011011000001111000001106
101010101111111110101010170
110011001111000011000000192

Usage

In the ALU (level 13), bus AND is one of the basic operations alongside OR, XOR and addition. The processor uses it to clear bits: before writing a new value, the target bits are wiped with a mask and then refilled. AND also helps with flags: apply a mask to the status byte and you can inspect one specific flag without touching the others.

The second role is parsing instruction bytes and reading devices. In the Harvard architecture (level 16) an instruction is packed into a single byte: the high 4 bits are the opcode, the low 4 bits the operand. Applying the mask 00001111, the processor instantly extracts the operand without touching the opcode. The same trick reads gamepad buttons and switches: the mask keeps only the bit you need. Finally, in levels 22–29 BusAND acts as a bus fuse: feed 00000000 into the mask input and you "disconnect" the data source from the shared bus, preventing a conflict where two devices pull the wire in different directions. Together with an address decoder, this is how exactly one device gets to drive the bus at any moment.

Build it yourself →

Related components

Related articles

Frequently Asked Questions

Where is bitwise AND used?

For masking: extracting selected bits of a number and checking set flags.

What happens if I feed zero into input B?

The output is always 00000000, whatever A is. This is how you "disconnect" a source from the shared bus: in levels 22–29 BusAND with a zero mask keeps two devices from fighting over one wire.

How do I extract the high nibble of a byte?

Apply the mask 11110000: A AND 11110000 zeroes the low 4 bits and passes the high bits unchanged. For example, 11011011 AND 11110000 = 11010000. For the low nibble the mask is mirrored — 00001111.