Skip to content
Digital circuitsCHIP Chair Logo

Numbers

In digital circuits, numbers are implemented in binary notation and all mathematical operations - addition, subtraction, comparison, multiplication, division or modulo - are performed by manipulating bits.

Example: Even or Odd Number

We will design a circuit that receives a 4-bit input number and activates the output (Parell=1) when the input number is even.

A binary number is even if its least significant bit (LSB) has the value 0.

We define the input variable:

nombre[3:0]=[nombre3 nombre2 nombre1 nombre0]

The least significant bit is nombre0.

The output is a single bit:

  • Parell=1 if the number is even.
  • Parell=0 if the number is odd.

Partial example table (the complete one would have 16 rows):

nombreNumber in decimalnombre0 (LSB)ParityParell
000000Even1
000111Odd0
001020Even1
001131Odd0
1110140Even1
1111151Odd0

Building the circuit is fairly straightforward; the output Parell must be activated (value 1) if and only if nombre[0] has the value 0, regardless of the value of the remaining bits of nombre.

Therefore, the output is the negation of nombre0.

Parell=nombre0

Thus, only a single NOT gate is required.

Parity circuit

Example: Modulo 7 of a 4-bit number

We will design a circuit that computes the modulo 7 of a binary number n, of 4 bits. Computing modulo 7 of a number consists of finding the remainder when it is divided by 7. The notation for this operation is:

residu=nmod7

A 4-bit number n[3:0]=[n3n2n1n0] can take 16 different values from 0000 to 1111 (0 to 15 in decimal).

The remainders after dividing a number by 7 can take values from 0 to 6. To represent the result of the operation, a 3-bit number will suffice, which can take values from 000 to 111 (0 to 7 in decimal).

residu[2:0]=[residu2 residu1 residu0]

The first step in designing this circuit is to create the complete truth table that relates each 4-bit input n[3:0] to its corresponding 3-bit remainder residu[2:0].

residu[2:0]=n[3:0]mod7

n (decimal)n3n2n1n0residu (decimal)residu2residu1residu0
000000000
100011001
200102010
300113011
401004100
501015101
601106110
701110000
810001001
910012010
1010103011
1110114100
1211005101
1311016110
1411100000
1511111001

For each output (residu0, residu1, residu2) a Karnaugh map with 4 variables is built to obtain its simplified Boolean expression.

Output residu0

We construct the Karnaugh map for the 4 input variables for the output residue_0 and identify 3 groups.

n1 n0
n3 n2
00011110
000 1 1 0
010 1 1 0
110 1 0 0
100 1 1 0
n1 n0
n3 n2
00011110
000 1 1 0
010 1 1 0
110 1 0 0
100 1 1 0

The simplified Boolean expression for residue_0 will have 3 terms:

residu0=n1n0+n3n0+n2n0

Output residu1

We build the Karnaugh map for the 4 input variables for the output residue_1 and identify 2 groups.

n1 n0
n3 n2
00011110
000 0 1 1
010 0 1 1
110 0 0 0
100 0 1 1
n1 n0
n3 n2
00011110
000 0 1 1
010 0 1 1
110 0 0 0
100 1 1 0

Aquesta expressió booleana simplified for residue_1 tindrà 2 termes:

residu1=n3n1+n2n1

Output residu2

For the output residue_2, identify 2 groups on its Karnaugh map.

n1 n0
n3 n2
00011110
000 0 0 0
011 1 1 1
111 1 0 0
100 0 0 0
en | 1 | | 1111 | 15 | 1 | Odd | 0 |
n1 n0
n3 n2
00011110
000 0 0 0
011 1 1 1
111 1 0 0
100 0 1 1

Thus, the simplified Boolean expression for residue_2 will have 2 terms:

residu2=n2n1+n3n2

From these three expressions we can use logic gates to create the digital circuit that will implement the function nmod7.

Circuit modulo 7

Exercises on Jutge.org: [Introduction to Digital Circuit Design]

Remember that to access the exercises and for the Jutge judge to evaluate your solutions you must be enrolled in the course. You will find all the instructions here.



CHIP Chair Logos

Xavier Casas, Francesc Madrid
Lliçons.jutge.org
© Universitat Politècnica de Catalunya, 2026

lliçons.jutge.org