Upload
ngoune
View
238
Download
0
Embed Size (px)
Citation preview
8/6/2019 Numeration Systems and Codes
1/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.
8/6/2019 Numeration Systems and Codes
2/21
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 afterminute, shows a digital representation.
8/6/2019 Numeration Systems and Codes
3/21
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:
Lets consider the decimal notation 1253. This number can be broken into its
constituent weight-products as such:
01231031051021011253
131051002100011253
35020010001253
+++=
+++=
+++=
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 lessweighted.
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
8/6/2019 Numeration Systems and Codes
4/21
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 and . 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:
Lets consider the following binary number
A = 1 0 1 1 0 12
10
012345
45
148032
212021212021
=
++++=
+++++=
A
A
A
Each weight is 2 that of the one in the immediate right. The less weighted
cipher carries the Ones place (20), the cipher at the immediate left carries the twos
place (21
), the following cipher carries the fourth place (22
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
8/6/2019 Numeration Systems and Codes
5/21
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- and -(by two
different voltages for example) than to materialises 10 different quantities ,
, and- (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 n2 different binary numbers. The higher H number is
given using the following formula.
12 =n
H (1)
8/6/2019 Numeration Systems and Codes
6/21
Digital Electronics_Jean-Paul NGOUNE 6
Example 1.4:
With 4 bits we can represent 24 = 16 different binary numbers (from 0 to 15), and the
higher number is H = 24 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
321
321012
625.5
2
1
2
0
2
1104
212021212021
=
+++++=
+++++=
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, andf.
To convert from binary to octal numeration system, we just have to divide thenumber 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:
Lets convert the following binary numbers in octal:
A = 10110101
B = 11010111.01
2 1 0 -1 -2 -3
8/6/2019 Numeration Systems and Codes
7/21
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.
1.3.5 Hexadecimal numeration system:
The hexadecimal numeration system is a place weighted system with a base
of sixteen. Valid ciphers include the normal decimal symbols
;9 plus six alphabetical characters A, B, C, D, E, and
F. The following table summarises the equivalence between decimal, binary, octal
and hexadecimal systems.
Decimal Binary Octal Hexadecimal0 0000 0 01 0001 1 12 0010 2 23 0011 3 34 0100 4 45 0101 5 56 0110 6 67 0111 7 78 1000 10 8
9 1001 11 910 1010 12 A11 1011 13 B12 1100 14 C13 1101 15 D14 1110 16 E15 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 58
101101012 = 2658
3 2 7 . 28
11010111.012 = 327.28
8/6/2019 Numeration Systems and Codes
8/21
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 D16
11010111012 = 35D16
7 5 D C16
11101011101.112 = 75DC16
8/6/2019 Numeration Systems and Codes
9/21
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 5238.
b) Convert the following hexadecimal number to binary 4DC216.
5238 = 101 010 0112
4DC216 = 0100 1101 1100 00102
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.748
A = 2 6 4. 7 48
10
21012
9375.180
6414
8171486642
8487848682
=
++++=
++++=
A
A
A
Exercise 1.3:
Convert the following octal number to decimal:
A = 4562.368 C = 264.3658
B = 523411.2328 D = 4516328
Is the number 12586 an octal number?
5 2 3
4 D C 2
5238 = 1010100112
4DC216 = 1001101110000102
2 1 0 -1 -2
8/6/2019 Numeration Systems and Codes
10/21
Digital Electronics_Jean-Paul NGOUNE 10
1.4.1.3 Hexadecimal to decimal:
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.AC216
A = 3 4 D F.A C 216
10
3210123
67236.13535
000488281.0046875.0625.015208102412288
1621612161016151613164163
=
++++++=
++++++=
A
A
A
Exercise 1.4:
Convert from hexadecimal to decimal.
X = A23C.DF16
Y = 7D3E16
Z = D96EC.FA16
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
8/6/2019 Numeration Systems and Codes
11/21
Digital Electronics_Jean-Paul NGOUNE 11
1.4.2.1 Decimal to binary conversion:
Let us convert the decimal number 8710 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:
210 101011187 =
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 = 15310 C = 4610
B = 25510 D = 3810
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.37510 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)
8/6/2019 Numeration Systems and Codes
12/21
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.37510 = 0.0112
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.812510 C = 0.87510
B = 0.62510 D = 0.4062510
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.12510
to binary.
Step one: repeated division for the integer portion 2310.
23 2
11 2 1
5 2 1
2 2 1
1 0
Partial answer:
2310 = 101112
Step two: repeated multiplication for the less than 1 portion 0.12510.
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
Partial answer:
0.12510 = 0.0012
Complete answer:
101112 + 0.0012 = 10111.0012
8/6/2019 Numeration Systems and Codes
13/21
Digital Electronics_Jean-Paul NGOUNE 13
Exercise 1.7:
Convert from decimal to binary
A = 17.37510 C = 27.87510
B = 43.62510 D = 49.4062510
1.4.2.3 Decimal to octal conversion:
Let us convert the number 12310 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
12310 = 1738
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 = 32310 C = 12810
B = 45210 D = 9910
1.4.2.4 Decimal to hexadecimal conversion:
Let us convert the number 45616 from decimal to hexadecimal. This
conversion is obtained by repeated division of the decimal number by 16.
456 16
28 16 8
1 12
(C16)
45616 = 1C816
8/6/2019 Numeration Systems and Codes
14/21
Digital Electronics_Jean-Paul NGOUNE 14
Exercise 1.8:
Convert from decimal to hexadecimal:
A = 452310 C = 99710
B = 86710 D = 123810
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 = 45610 to BCD.
A = 4 5 6 Decimal
A = 010001010110BCD
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 = 683910
Y =0111 1100 0001
0100 0101 0110 BCD
6 8 3 9
7 ? 1
8/6/2019 Numeration Systems and Codes
15/21
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 = 153610 C = 5698910
B = 8975610 D = 23569810
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 1910 to binary and to BCD:
3510 = 1000112
3510 = 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 binarysystem where many bits can change when we move from a number to the following
8/6/2019 Numeration Systems and Codes
16/21
Digital Electronics_Jean-Paul NGOUNE 16
number. For example, when we move from 0111 (710) to 1000 (810), 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
8/6/2019 Numeration Systems and Codes
17/21
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 wasnt 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 +, /,>,
8/6/2019 Numeration Systems and Codes
18/21
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
8/6/2019 Numeration Systems and Codes
19/21
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 = 110112 D = 10010.0112
B = 10111012 E = 101001111112
C = 10111112 F = 1110111.00012
3. Convert from binary to octal:
A = 111011.011012 D = 111011111012
B = 101101112 E = 10011101.1102
C = 11011110.01012 F = 100111101011112
8/6/2019 Numeration Systems and Codes
20/21
Digital Electronics_Jean-Paul NGOUNE 20
4. Convert from binary to hexadecimal.
A = 1111010.11102 C = 111010111.112
B = 101111101111012 D = 10110110.1111012
5 Convert from octal to binary:
A = 1238 C = 3578
B = 6538 D = 5478
6 Convert from hexadecimal to binary.
X = F47B16 Z = 8CE016
Y = 5FD316 P = FFFC16
7 Convert from octal to decimal :
A = 1258 C = 5638
B = 2568 D = 4538
8. Convert from hexadecimal to decimal:
X = F47B16 Z = 8CE016
Y = 5FD.316 P = FFF.C16
9. Convert from decimal to binary:
A = 2310 C = 5310
B = 25.37510 D = 101.2510
10. Convert from decimal to octal:
A = 42310 C = 43810
B = 126410 D = 342310
11. Convert from decimal to hexadecimal:
A = 126210 C = 256310
B = 356210 D = 56423610
12. Convert from octal to hexadecimal:A = 123.628 B = 432.58
8/6/2019 Numeration Systems and Codes
21/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
hexadecimal. Those addresses are sequential numbers that identify each
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 000016 to
FFFF16, 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
addresses starting from 000016.
15 Determine the number of bits to be used to represent the decimal numbers
from 00010 to 99910: 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, 3rd edition,
Prentice-Hall inc., Englewood Cliffs, New Jersey , USA,1985.
2. Lessons In Electric Circuits Volume IV Digital, Tony R. Kuphaldt, Fourth
Edition, 2007, www.allaboutcircuits.com. www.ibiblio.org/obp/electricCircuits.
http://www.allaboutcircuits.com/http://www.allaboutcircuits.com/http://www.ibiblio.org/obp/electricCircuitshttp://www.ibiblio.org/obp/electricCircuitshttp://www.allaboutcircuits.com/