Home › Practice › RTL Design › Divisible by 3?
Divisible by 3?
EasyRTLsequentialfsm
The bits of a binary number arrive one per clock, biggest bit first. After each bit, the circuit must say whether the number so far is a multiple of 3.
Concept first. You do not need to remember the whole number, only its remainder when divided by 3. That is only three possible values, so three states are enough, however long the number gets. When a new bit arrives, the number doubles and the new bit is added. Compare with decimals: when a new digit arrives, the number is multiplied by 10 and the digit is added, so 12 followed by 7 is 127. Use that to find the new remainder from the old one and the new bit. Build the small table with the 3 remainders as rows and the bit 0 or 1 as columns.
What to build.
- Inputs
clk,rst,b. Outputdiv. rstis synchronous and sets the number so far to 0.divis 1 when the number formed by all bits received since reset is divisible by 3. Zero counts as divisible, sodivis 1 right after reset.- Bits arrive biggest first, so after the bits 1, 1 the number is 3.
No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.