How this instrument works
A bitwise operation combines two binary numbers place by place, entirely independently — the result at bit 3 depends only on the two inputs' own bit 3, never on any other place, and the same goes for every other slot in turn. This page computes two of the most common bitwise operations, AND and OR, across all four bits of two 4-bit numbers at once.
Each individual bit combination reuses the identical arithmetic identities this site's Truth Table calculator introduces for single 0/1 values: AND at a given spot is that spot's product, and OR is the sum minus the product, correcting for double-counting the case where both bits already hold a 1. Applying those same two identities four times, once per bit, builds up the full 4-bit result.
AND is useful for MASKING — clearing out bits you don't want by combining with a pattern of 0s and 1s — while OR is useful for SETTING specific bits on without disturbing any others, two of the most common building blocks in low-level programming.
- Enter number A's four bits, from bit 3 down to bit 0.
- Enter number B's four bits the same way.
- Read AND bit 3 through bit 0 — only positions where BOTH inputs hold a 1 survive.
- Read OR bit 3 through bit 0 — any position where EITHER input holds a 1 survives.
Worked example — 1011 AND/OR 1101
A (1011) and B (1101), combined bit by bit: AND gives 1001 (only spots where both hold a 1 survive — bit 3 and bit 0), and OR gives 1111 (any spot where either holds a 1 survives — every one of the four here has at least one 1 somewhere).
A (1111) AND B (0000) gives 0000, since B has no 1s anywhere for A's own 1s to match against; A OR B in that same case gives 1111, since A already has every bit switched on. Two identical patterns (1010 and 1010) give that same pattern back unchanged under both AND and OR — combining a pattern with itself never changes it.
Questions
What does bitwise AND do?
It compares two numbers bit by bit, keeping a 1 at any spot only where BOTH numbers already have a 1 there — every other slot becomes 0, making AND useful for clearing (masking out) specific bits.
What does bitwise OR do?
It compares two numbers bit by bit, setting a 1 at any spot where EITHER number already has a 1 there — only slots where both are 0 stay 0, making OR useful for setting specific bits on.
How is this different from the Truth Table calculator on this site?
That page computes AND, OR, and XOR for a single pair of 0/1 values; this page applies those same identities four separate times, once per bit, to combine two full 4-bit numbers at once.
What is bit masking?
Using a bitwise AND with a carefully chosen pattern of 0s and 1s to clear out specific bits from a number while leaving the rest untouched — a common low-level programming technique this page's AND result demonstrates directly.
Why does this page enter numbers as separate bits rather than as decimal values?
Because bitwise operations act on each INDIVIDUAL bit directly, entering every one explicitly makes that bit-by-bit combination visible, rather than hiding it inside a single decimal number that would need converting first.