Lesson 9 of 15
Half Adder
Half Adder
A half adder adds two single bits and produces two outputs:
- Sum (S): the XOR of the inputs — the result bit
- Carry (C): the AND of the inputs — the carry to the next bit position
| A | B | Sum | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
When 1 + 1 = 2 in binary is 10: sum bit is 0, carry bit is 1.
The half adder is called "half" because it cannot handle a carry-in from a previous addition — for that, you need a full adder.
Circuit
S = A XOR B
C = A AND B
Your Task
Implement halfAdder(a, b) that returns an object { sum, carry }.
Then print the result of adding 1+1 and 1+0.
JavaScript loading...
Loading...
Click "Run" to execute your code.