Sie sind auf Seite 1von 21

# Digital Electronics_Jean-Paul NGOUNE

1
Courses In
Electrical
Engineering
Volume II
DIGITAL ELECTRONICS
CHAPTER ONE : NUMERATION SYSTEMS AND CODES
By
J-P. NGOUNE
DIPET I ( Electrotechnics), DIPET II (Electrotechnics)
DEA ( Electrical Engineering)
Teacher in the Electrical Department, GTHS KUMBO, Cameroon.
Digital Electronics_Jean-Paul NGOUNE
2
Chapter One
NUMERATION SYSTEMS
AND CODES
1.0 Specific objectives:
At the end of this chapter, the student will be able to:
- know binary, hexadecimal and octal numeration systems;
- Know Gray, BCD and ASCII codes;
- Master the principle of conversion from each numeration system to another.
1.1 Introduction:
Numbers are used to express quantities. There are many numerations
systems used in the field of digital electronics, one of the most important being the
binary system of numeration on which is based the computer science. Each of the
various numerations systems and codes has its advantages but also inconvenient.
The aim of this chapter is to present and explain the most common numeration
systems and codes used in the conception of digital circuits.
1.2 Digital versus Analogue representation:
There are two basic ways we can represent quantities: Analogue
representation and digital representation. With analogue representation, the quantity
is symbolised in a way that is infinitely divisible. With digital representation, the
quantity is symbolised in a way that is discretely packaged.
Example 1.1:
The height of the red column which indicates the temperature measured by a
thermometer is an analogue representation.
An electronic watch whose digits changes second after second, minute after
minute, shows a digital representation.
Digital Electronics_Jean-Paul NGOUNE
3
The comparison between digital and analogue representations can be given as in the
following chart:
Analogue representation Digital representation
Infinitely divisible Discrete (Step by step)
Prone to errors of precision Absolute precision
1.3 Systems of numeration:
To represent quantities in the different systems of numeration, specific
symbols are used, which are also called ciphers.
1.3.1 Decimal numeration system:
Decimal system is the most common numeration system for daily uses. It is
constituted by 10 symbols or ciphers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Each cipher
represents an integer quantity and each place from right to left in a decimal notation
represents a weight for each integer quantity.
Example 1.2:
Let's consider the decimal notation 1253. This number can be broken into its
constituent weight-products as such:
0 1 2 3
10 3 10 5 10 2 10 1 1253
1 3 10 5 100 2 1000 1 1253
3 50 200 1000 1253
+ + + =
+ + + =
+ + + =
We can easily notice that the cipher 1 is more weighted than the cipher 2
which in his turn is more weighted than the cipher 5. The cipher 3 is the less
weighted.
In the decimal numeration system, each cipher is called a digit. Each weight or
place value is ten that of the one to the immediate right. The less weighted cipher
carries the One place, the cipher at the immediate left carries the Tens place, the
follower carries the Hundreds place, thousands place, and so on.
Digital Electronics_Jean-Paul NGOUNE
4
1.3.2 Binary numeration system:
The binary numeration system uses only two ciphers instead of ten as the
decimal numeration system. Those two ciphers are "0 and "1. In binary system of
numeration, ciphers are called bit (Binary Digit). Cipher are arranged right to left in
doubling values of weight ( instead of multiplying the weight by 10 as in the case of
decimal system).
Example 1.3:
Let's consider the following binary number
A = 1 0 1 1 0 1
2
10
0 1 2 3 4 5
45
1 4 8 0 32
2 1 2 0 2 1 2 1 2 0 2 1
=
+ + + + =
+ + + + + =
A
A
A
Each weight is 2 that of the one in the immediate right. The less weighted
cipher carries the Ones place (2
0
), the cipher at the immediate left carries the twos
place (2
1
), the following cipher carries the fourth place (2
2
).
Exercise 1.1:
Convert the following binary numbers to decimal numbers:
A = 110101 C = 11110111101
B = 100110101 D = 101100001111
5 4 3 2 1 0
Base 2
Weights
Digital Electronics_Jean-Paul NGOUNE
5
1.3.3 Binary versus decimal numeration system:
Let us count from 0 to 15 using binary and decimal systems of numeration
Binary
D(MSB) C B A(LSB) Decimal
0 0 0 0 0
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
1 0 0 1 9
1 0 1 0 10
1 0 1 1 11
1 1 0 0 12
1 1 0 1 13
1 1 1 0 14
1 1 1 1 15
It is obvious that the representation of a quantity in binary numeration system
takes mores ciphers than in decimal system. We can therefore ask ourselves why the
binary system is preferred to decimal system in computer sciences. The reason is
that in electronics, it is easier to materialise two quantities-"0 and "1-(by two
different voltages for example) than to materialises 10 different quantities "0 ,1
,2,3,4,5,6,7,8, and9- (by 10 different voltages). In fact, in digital circuits, 0
and 1 are materialised by specific ranges of voltages or current; this will be discussed
later.
Remark 1.1:
With n bits we can represent
n
2 different binary numbers. The higher H number is
given using the following formula.
1 2 =
n
H (1)
Digital Electronics_Jean-Paul NGOUNE
6
Example 1.4:
With 4 bits we can represent 2
4
= 16 different binary numbers (from 0 to 15), and the
higher number is H = 2
4
1 = 15.
Remark 1.2: Conversion from binary to decimal
To convert a number written in binary numeration system to its equivalent in
decimal, we just have to calculate the products of the bits with their respective
weights, as in example 1.3 above.
For binary numbers with "binary point (equivalent of decimal point for decimal
numbers), the conversion is done as follow.
A = 1 0 1. 1 0 1
10
3 2 1
3 2 1 0 1 2
625 . 5
2
1
2
0
2
1
1 0 4
2 1 2 0 2 1 2 1 2 0 2 1
=
+ + + + + =
+ + + + + =

A
A
A
Exercise 1.2:
Convert from binary to decimal:
A = 10110.01 C = 11110111.1011
B = 111.111 D = 10110101101.111101
1.3.4 Octal numeration system:
The octal numeration system is a place weighted system with a base of eight.
Valid ciphers include the symbols "0,1,2,3,4,5,6, andf7.
To convert from binary to octal numeration system, we just have to divide the
number into groups of binary numbers having 3 bits each. And each group of 3 bits is
replaced by its equivalent in octal.
Example 1.5:
Let's convert the following binary numbers in octal:
A = 10110101
B = 11010111.01
2 1 0 -1 -2 -3
Digital Electronics_Jean-Paul NGOUNE
7
A = 010 110 101
The bits are grouped from the right to the left. A zero has been added to the
two firs bits to form a group of 3 bits. That zero is called an implied zero.
B = 011 010 111 . 010
Two implied zeros have been added to the number to form groups of 3 bits.
The hexadecimal numeration system is a place weighted system with a base
of sixteen. Valid ciphers include the normal decimal symbols
"0,1,2,3,4,5,6,7;8;9 plus six alphabetical characters A, B, C, D, E, and
F. The following table summarises the equivalence between decimal, binary, octal
0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
To convert from binary to hexadecimal numeration, we group bits in fours.
Each group of four bit is replaced by its hexadecimal equivalent.
2 6 5
8
10110101
2
= 265
8
3 2 7 . 2
8
11010111.01
2
= 327.2
8
Digital Electronics_Jean-Paul NGOUNE
8
Example 1.6:
Convert the following binary numbers in hexadecimal.
A = 1101011101
B = 11101011101.11
As explained above, we just have to group the binary number in groups of four bits
each:
A =0011 0101 1101
The binary number has been grouped is groups of four bits each, from the right to the
left two implied zeros have been added at the extreme left. In the same way the
number B can also be converted.
B =0111 0101 1101 . 1100
1.4 Changing of base:
We have already seen in the previous section how to change from binary to
decimal, octal or hexadecimal systems of numeration. The present section is
intended to show how to move from a given system of numeration to any other
system.
1.4.1 From octal and hexadecimal to binary and decimal:
The octal and hexadecimal systems are actually used by computer engineer
just to obtain a "shorthand representation of binary numbers (because octal and
hexadecimal representations take a few numbers of ciphers or symbols as compared
to binary system). It should therefore be understood that only binary system is
implemented in the electronic circuits of digital systems (through two levels of
voltages or currents: high (1) and low (0)), the others systems being used by
engineers just for simplification issues.
However, we sometimes have the need to convert either of those systems to
binary or decimal forms.
3 5 D
16
1101011101
2
= 35D
16
7 5 D C
16
11101011101.11
2
= 75DC
16
Digital Electronics_Jean-Paul NGOUNE
9
1.4.1.1 Octal and hexadecimal to binary:
It is obvious that, to convert from octal to binary, we just have to convert each
octal cipher to its binary equivalent in 3 bits. In the same way, to convert from
hexadecimal to binary, we should convert each hexadecimal symbol into its binary
equivalent in 4 bits.
Example 1.7:
a) Convert the following octal number to digital 523
8.
b) Convert the following hexadecimal number to binary 4DC2
16
.
523
8
= 101 010 011
2
4DC2
16
= 0100 1101 1100 0010
2
1.4.1.2 Octal to decimal:
Because octal is a base of eight numeration system, each place weight value
differs from either adjacent place by factor of eight.
Example 1.8:
Let us convert the following octal number to decimal: A = 264.74
8
A = 2 6 4. 7 4
8
10
2 1 0 1 2
9375 . 180
64
1
4
8
1
7 1 4 8 6 64 2
8 4 8 7 8 4 8 6 8 2
=
+ + + + =
+ + + + =

A
A
A
Exercise 1.3:
Convert the following octal number to decimal:
A = 4562.36
8
C = 264.365
8
B = 523411.232
8
D = 451632
8
Is the number 12586 an octal number?
5 2 3
4 D C 2
523
8
= 101010011
2
4DC2
16
= 100110111000010
2
2 1 0 -1 -2
Digital Electronics_Jean-Paul NGOUNE
10
The technique for converting hexadecimal notation to decimal is the same as
the one used above, except that each successive place weight changes by a factor
of sixteen.
Example 1.9:
Let us convert the following hexadecimal number to decimal: A = 34DF.AC2
16
A = 3 4 D F.A C 2
16
10
3 2 1 0 1 2 3
67236 . 13535
000488281 . 0 046875 . 0 625 . 0 15 208 1024 12288
16 2 16 12 16 10 16 15 16 13 16 4 16 3
=
+ + + + + + =
+ + + + + + =

A
A
A
Exercise 1.4:
X = A23C.DF
16
Y = 7D3E
16
Z = D96EC.FA
16
1.4.2 Conversion from decimal numeration system to others systems:
The conversion from decimal numeration system to others systems of
numeration is an important task for everyone dealing with computer science, because
it permits to move from daily world to digital world.
1.4.2.1 General method:
To convert a number from decimal numeration system to binary, octal or
hexadecimal, we use repeated cycles of divisions to break the decimal numeration
down into multiples of binary, octal or hexadecimal place weight values.
In the first cycle of division, we take the original decimal number and divide it
by the base of the numeration system that we are converting to: It meant that for
binary, we should divide by 2, for octal we should divide by 8, for hexadecimal we
should divide by 16. Then we take the whole number portion of the division result and
divide it by the result again, and so on, until we end up with a quotient of less than
the base value.
3 2 1 0 -1-2-3
Digital Electronics_Jean-Paul NGOUNE
11
1.4.2.1 Decimal to binary conversion:
Let us convert the decimal number 87
10
to binary, using the principle
described above. It meant that the decimal number should be repeatedly divided by
2.
87 2
43 2 1
21 2 1
10 2 1
5 2 0
2 2 1
1 0
The coloured ciphers are the reminders of repeated division of the decimal
number by 2. To obtain the binary number, we just have to take those reminders,
beginning with the last one, as indicated by the arrow. Then we have:
2 10
1010111 87 =
In short, the binary bits are assembled from the reminders of the successive
division steps, beginning with the LSB (Least Significant Bit) and proceeding to the
MSB (Most significant Bit).
Exercise 1.5:
Convert the following decimal numbers to binary
A = 153
10
C = 46
10
B = 255
10
D = 38
10
1.4.2.2 Conversion of decimal numbers less than 1 to binary:
For converting a decimal number less than 1 to binary, we use repeated
multiplication by 2, taking the integer portion of the product in each step as the next
digit of our converted number. Let us convert the decimal number 0.375
10
to binary:
0.375x2 = 0.75 Integer portion of the product = 0
0.75x2 = 1.5 Integer portion of the product = 1
0.5x2 = 1 Integer portion of the product = 1
(we stop when the product is a pure integer)
Digital Electronics_Jean-Paul NGOUNE
12
Each step gives us the next bit further away from the binary point, so the
binary number is obtained taking the bits from up to down.
0.375
10
= 0.011
2
Remark 1.3:
With integer division, worked from the LSB to the MSB (down to up), but with
repeated multiplication, we worked from up to down.
Exercise 1.6:
Convert from decimal to binary:
A = 0.8125
10
C = 0.875
10
B = 0.625
10
D = 0.40625
10
Remark 1.4:
To convert a decimal number greater than 1 with a less than 1 component, we
should use both techniques, one at time. Let us convert the decimal number 23.125
10
to binary.
Step one: repeated division for the integer portion 23
10
.
23 2
11 2 1
5 2 1
2 2 1
1 0
23
10
= 10111
2
Step two: repeated multiplication for the less than 1 portion 0.125
10
.
0.125x2 = 0.25 Integer portion of the product = 0
0.25x2 = 0.5 Integer portion of the product = 0
0.5x2 = 1 Integer portion of the product = 1
0.125
10
= 0.001
2
10111
2
+ 0.001
2
= 10111.001
2
Digital Electronics_Jean-Paul NGOUNE
13
Exercise 1.7:
Convert from decimal to binary
A = 17.375
10
C = 27.875
10
B = 43.625
10
D = 49.40625
10
1.4.2.3 Decimal to octal conversion:
Let us convert the number 123
10
from decimal to octal numeration system. As
explained before, we just have to divide the decimal number successively by 8.
123 8
15 8 3
1 7
123
10
= 173
8
The octal digits are determined by the reminders left over by each division
step. These reminders are between 0 and 7.
Exercise 1.7:
Convert the following numbers from decimal to octal:
A = 323
10
C = 128
10
B = 452
10
D = 99
10
Let us convert the number 456
16
conversion is obtained by repeated division of the decimal number by 16.
456 16
28 16 8
1 12
(C
16
)
456
16
= 1C8
16
Digital Electronics_Jean-Paul NGOUNE
14
Exercise 1.8:
A = 4523
10
C = 997
10
B = 867
10
D = 1238
10
1.5 Codes:
A code is a system of letters, numbers or symbols that represent information.
We have seen in previous sections that every decimal number can be converted in
binary; by so doing, we can say that we are achieving a pure binary codification.
There are many codes used in computer science to facilitate the operation of certain
digital circuits. Some of those codes are: BCD code, Gray code, and alphanumerical
codes.
1.5.1 Binary coded decimal (BCB) code:
The BCD code of a decimal number is obtained by replacing each digit of the
number by its equivalent in four bits, within the interval 0000 to 1001. Because of the
fact that the maximal digit of the decimal numeration system is 9, the allowable codes
goes from 0 (0000) to 9 (1001). So, the BCD code does not use the codes 1010,
1011, 1100, 1101, and 1111.
Let us convert the number A = 456
10
to BCD.
A = 4 5 6 Decimal
A = 010001010110
BCD
Example 1.10:
Convert the following BCD number in decimal: X = 0110100000111001. Can the
following series of bits be the BCD code of a decimal number? Y = 011111000001.
X = 0110 1000 0011 1001
X = 6839
10
Y =0111 1100 0001
0100 0101 0110 BCD
6 8 3 9
7 ? 1
Digital Electronics_Jean-Paul NGOUNE
15
The second group of bit (1100) is not allowable in the BCD code, so the number Y
cannot be the BCD code of a decimal number.
Exercise 1.9:
Determine the equivalent BCD code of the following decimal numbers:
A = 1536
10
C = 56989
10
B = 89756
10
D = 235698
10
Determine if possible the decimal numbers corresponding to the following BCD
numbers:
A = 100101110110
B = 110111100111
Remark 1.5: Difference between BCD code and binary number
It is important to realise that the BCD code is not a numeration system as
binary, octal or hexadecimal numerations systems. In fact, it is just a decimal system
whose digits have been replaced by their binary equivalent in four bits. On the other
hand it should be noticed that a BCD number is not a binary number. When we are to
convert a decimal number to binary, the whole number is taken into consideration
meanwhile to convert from decimal to BCD, each individual digit is replaced by its
binary equivalent in four bits.
For example, let us convert 19
10
to binary and to BCD:
35
10
= 100011
2
35
10
= 0011 0101 (BCD).
It is obvious that the conversion from binary to BCD takes more bits than the
conversion from decimal to binary. So the BCD code is not as efficient as the binary
system. The advantage of the BCD code is just the fact that it is very easy to convert
from decimal to BCD and vice versa.
The BCD code is found in digital systems using 7 segments displays like
digital voltmeters, digital watch.
1.5.2 Gray code:
The Gray code is a non weighted code in which each coded representation
differs from the previous representation only by one bit. It is not the case for binary
system where many bits can change when we move from a number to the following
Digital Electronics_Jean-Paul NGOUNE
16
number. For example, when we move from 0111 (7
10
) to 1000 (8
10
), all the four bits of
the representation are changed. The Gray code is not suitable for arithmetical
calculations (because it is not weighted); it is used in the determination of outputs
equations of digital circuits ( Karnaugh mapping) and in the design of Analog
Digital Converters.
The following table gives us the equivalence between binary representation
and Gray code.
Decimal Binary Gray
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
Remark 1.6: How to generate a Gray sequence
If you observe attentively the Gray sequence above, you will notice that:
For the first column of ciphers (coming from the right to the left), the first zero
is followed by two ones, which are followed by two zeros, two ones, two
zeros.
For the next column of ciphers you can notice that the two first zeros are
followed by four ones, which are followed by four zeros, four ones.
Digital Electronics_Jean-Paul NGOUNE
17
For the third column of ciphers, the four first zeros are followed by eight ones,
which are followed by eight zeros, eight ones.
This is the principle to be used in order to generate a Gray sequence.
1.5.3 Alphanumerical codes
A computer would have been useless if it wasn't able to treat non numerical
information. In fact, a computer should be able to recognize codes corresponding to
numbers, letters or some special characters. Such codes are called alphanumerical
codes. Generally the keyboard of a computer should contain the following symbols:
The 26 letters of the alphabet (capital and small letters);
The 10 ciphers of the decimal numeration system,
Almost 25 special characters like +, /,>, <, @, %...
There are almost 87 characters and to represent those characters, we need at
least 7 bits because with 7 bit, we can have up to 2
7
= 128 different binary numbers.
So, we use 87 of those binary numbers to codify the 87 characters.
The most known alphanumerical code is called American Standard code for
Information Interchange (ASCII). This code is used by almost all the computer
constructors.
The following table gives the ASCII code corresponding to some of the
characters.
A 100 0001 101 41
B 100 0010 102 42
C 100 0011 103 43
D 100 0100 104 44
E 100 0101 105 45
F 100 0110 106 46
G 100 0111 107 47
H 100 1000 110 48
I 100 1001
J 100 1010
K 100 1011
Digital Electronics_Jean-Paul NGOUNE
18
L 100 1100
M 100 1101
N 100 1110
O 100 1111
P 101 0000
Q 101 0001
R 101 0010
S 101 0011
T 101 0100
U 101 0101
V 101 0110
W 101 0111
X 101 1000
Y 101 1001
Z 101 1010
0 011 0000
1 011 0001
2 011 0010
3 011 0011
4 011 0100
5 011 0101
6 011 0110
7 011 0111
8 011 1000
9 011 1001
Blank 010 0000
. 010 1110
( 010 1000
+ 010 1011
\$ 010 0100
* 010 1010
) 010 1001
- 010 1101
Digital Electronics_Jean-Paul NGOUNE
19
/ 010 1111
, 010 1100
= 011 1101
Exercise 1.10:
Give the octal and hexadecimal equivalent for all the ASCII codes given
above.
The following instruction coded in ASCII is composed on the keyboard of a
computer. Give its signification: 101 0011, 101 0100, 100 1111, 101 0000.
Answer: Using the table above we find that the instruction is STOP.
1.6 Conclusion
This chapter has permitted us to study and to master (I hope so) the most
common numeration systems and codes. We have also studied methods of
conversion from each numeration system to another. In the next chapter, we will
study the behaviour of logic gates, which can be considered as elementary 'bricks'
used in the construction of any digital circuit.
REVIEW QUESTIONS
1. Give the difference between analogue and digital representations.
2. Convert from binary to decimal:
A = 11011
2
D = 10010.011
2
B = 1011101
2
E = 10100111111
2
C = 1011111
2
F = 1110111.0001
2
3. Convert from binary to octal:
A = 111011.01101
2
D = 11101111101
2
B = 10110111
2
E = 10011101.110
2
C = 11011110.0101
2
F = 10011110101111
2
Digital Electronics_Jean-Paul NGOUNE
20
4. Convert from binary to hexadecimal.
A = 1111010.1110
2
C = 111010111.11
2
B = 10111110111101
2
D = 10110110.111101
2
5 Convert from octal to binary:
A = 123
8
C = 357
8
B = 653
8
D = 547
8
6 Convert from hexadecimal to binary.
X = F47B
16
Z = 8CE0
16
Y = 5FD3
16
P = FFFC
16
7 Convert from octal to decimal :
A = 125
8
C = 563
8
B = 256
8
D = 453
8
8. Convert from hexadecimal to decimal:
X = F47B
16
Z = 8CE0
16
Y = 5FD.3
16
P = FFF.C
16
9. Convert from decimal to binary:
A = 23
10
C = 53
10
B = 25.375
10
D = 101.25
10
10. Convert from decimal to octal:
A = 423
10
C = 438
10
B = 1264
10
D = 3423
10
11. Convert from decimal to hexadecimal:
A = 1262
10
C = 2563
10
B = 3562
10
D = 564236
10
12. Convert from octal to hexadecimal:
A = 123.62
8
B = 432.5
8
Digital Electronics_Jean-Paul NGOUNE
21
13 Determine the highest decimal number that can be represented using 8bits, 16
bits.
14 In most of the computers, the addresses of memory locations are expressed in
memory location.
a) A computer can store data of 8 bits (1byte) in each of his memory
location. If the addresses of the memory locations run from 0000
16
to
FFFF
16
, then give the number of memory locations of that computer.
Deduce the capacity of its memory.
b) Another computer has 4096 memory locations. Give the interval of their
16
.
15 Determine the number of bits to be used to represent the decimal numbers
from 000
10
to 999
10
: a) using pure binary code b) using BCD code.
16 Express in ASCII the following instruction: "X = 25/Y
17 Convert from BCD to binary: A = 01110100 (BCD).
References:
1. Digital systems, principles and applications, Ronald J.Tocci, 3
rd
edition,
Prentice-Hall inc., Englewood Cliffs, New Jersey , USA,1985.
2. Lessons In Electric Circuits Volume IV Digital, Tony R. Kuphaldt, Fourth