Master the fundamental concepts of digital logic & boolean algebra through this focused micro-challenge.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksA half-adder adds two single-bit inputs and produces a sum bit plus a carry-out. It is the atomic building block inside every arithmetic unit, from a 4-bit student ALU to the 64-bit adders in modern x86 cores.
For example, adding 1 + 1 gives sum 0 and carry 1, which is binary 10.
cLoading…
A full-adder adds three bits: A, B, and Cin from the previous stage. Two half-adders plus an OR gate form the standard textbook design.
A + B produces intermediate sum and carryCinFor this exercise, you will wire half-adders into a full-adder using only the gate primitives you already built. You will need carry propagation correct before the ripple-carry adder in the next task can produce 3 + 5 = 8 on four bits.
Keep the relevant datasheet, ISA manual, or architecture textbook chapter open while you implement. When your output disagrees with the reference trace on the same program, the bug is usually a mis-decoded opcode, a stale register read, or a flag bit left unchanged after arithmetic.
For this exercise, you will use those habits while implementing the requirement in the starter code. Microarchitectural product names change across CPU generations, but the control ideas (fetch, bypass, cache lines, vector lanes) stay stable enough to debug from first principles.
Build the circuits that add bits. A half adder adds two bits; a full adder also adds a carry-in, and is built from two half adders plus an OR gate. Evaluate both, including the internal signals of the full adder, and print their truth tables.
cLoading…
One command per line:
| Command | Output |
|---|---|
half A B | half(A,B): sum=S carry=C |
full A B CIN | full(A,B,CIN): ha1 sum=S1 carry=C1; ha2 sum=S2 carry=C2; sum=S cout=C |
table half | header `a b |
table full | header `a b cin |
Table rows count up in binary with a as the most significant bit.
Errors (one line each): any input that isn't 0 or 1 → error: inputs must be 0 or 1; the wrong number of inputs → error: half takes 2 inputs / error: full takes 3 inputs; table X for any other X → error: unknown command table X; any other first word → error: unknown command WORD.
Input:
cLoading…
Output:
cLoading…
half_adder returns both outputs (a struct or two out-parameters); full_adder must call half_adder twice rather than use +.Hidden tests print both truth tables and cover every error message.