Home › Practice › RTL Design › How many lights are on?

How many lights are on?

EasyRTLcombinationalarithmetic

A parking sensor row has 4 bits, one per space, and a 1 means a car is parked there. The display must show how many cars there are.

Concept first. Counting ones is addition in disguise: each bit is a number that is either 0 or 1, so the number of ones is what you get when you add the four bits. How wide must the answer be? Four bits can add up to at most 4, and 4 needs three bits (100). So the answer has one more bit than you might expect. Check with a few inputs: 0110 has two ones, 1111 has four.

What to build.

Solve in your browser →

No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.

More in this track

← Running lights2-bit branch predictor →