Lesson 11 of 15

Ripple Carry Adder

Ripple Carry Adder

A ripple carry adder chains n full adders to add two n-bit numbers. The carry ripples from the least significant bit to the most significant bit.

To add two 4-bit numbers A = 0101 (5) and B = 0011 (3):

Bit 0: FA(1, 1, 0) → sum=0, carry=1
Bit 1: FA(0, 1, 1) → sum=0, carry=1
Bit 2: FA(1, 0, 1) → sum=0, carry=1
Bit 3: FA(0, 0, 1) → sum=1, carry=0
Result: 1000 = 8  ✓

The inputs a and b are arrays of bits with index 0 = LSB.

Your Task

Implement rippleCarryAdder(aBits, bBits) where:

  • aBits and bBits are arrays of bits, LSB first
  • Returns { sum: [...bits], carry: finalCarry }

Then add 5 (0101) and 3 (0011) as 4-bit numbers and print the sum bits and the decimal result.

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