Chapter 1 Min
Chapter 1 Min
1.1 Introduction
Digital quantities can only take on discrete values while analog quantities vary over
a continuous range of values. Examples of analog quantities include temperature,
speed. A digital system is a combination of devices designed to manipulate phys-
ical quantities that are represented in digital form as opposed to analog systems
which manipulate systems which are represented in analog form. Examples of dig-
ital systems include electronic calculators, digital watches, digital voltmeters and
digital computers. Examples of analog devices include pointer-type instruments like
speedometers, voltmeters, analog computers, etc. Advantages of digital systems over
analog quantities are:
All number systems are based on an ordered set of numbers called digits. The total
number of digits used in a system is called the base or radix of the system e.g. base
10 (or radix 10) uses then ten digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. The four number
systems that are used in digital systems are:
page 5 of 101
2
iii) Octal
iv) Hexadecimal - This number system, along with the Octal system are used as
shorthand notation for the Binary number system.
This is a positional-value system, that is, the value of a digit depends on its position in
the number. It is possible to design a digital system with ten states (decimal) but this
would not be easy to design as it would mean designing a circuit with ten discrete
voltage levels.
PSfrag replacements
This is known as Base 2 or Radix 2. Uses only two digits, 0 and 1. In digital systems,
these two digits are known as bits. The binary system is a positional value system,
with the weights weights as shown in Figure 1.1.
binary point
The decimal equivalent of the binary number an an−1 · · · a1 a0 .a−1 a−2 · · · a−m is given
by:
Example:
1010.1012 = (23 ×1)+(22 ×0)+(21 ×1)+(20 ×0)+(2−1 ×1)+(2−2 ×0)+(2−3 ×1) = 10.62510
page 6 of 101
3
Integers For integers, we use repeated division by 2 (also known as successive divi-
sion by 2). The example shown on Figure 1.2 shows how to apply this method
PSfrag replacements
to convert 5310 to binary.
2 53
2 26 R1
2 13 R0
2 06 R1
2 03 R0
2 01 R1
00 R1
The binary number is read in the direction shown by the arrow (upwards). In
this case, we can see that 5310 = 1101012
Fractions In this case we use repeated (or successive) multiplication by 2. The table
below shows this procedure to convert 0.812510 to binary.
DECIMAL BINARY
0.8125 × 2 = 1.625
1.625 − 1 = 0.625 1
0.625 × 2 = 1.250
1.250 − 1 = 0.250 1
0.250 × 2 = 0.500
0
0.500 × 2 = 1
1−1 = 0 1
page 7 of 101
4
DECIMAL BINARY
0.485 × 2 = 0.970
0
0.970 × 2 = 1.940
1.940 − 1 = 0.940 1
0.940 × 2 = 1.880
1.880 − 1 = 0.880 1
0.880 × 2 = 1.760
1.760 − 1 = 0.760 1
0.760 × 2 = 1.520
1.520 − 1 = 0.520 1
0.520 × 2 = 1.040
1.040 − 1 = 0.040 1
0.040 × 2 = 0.080
0
0.080 × 2 = 0.160
0
.. ..
. .
From the above computations, we can see that 0.48510 cannot be represented in
binary using a finite number of bits, hence 0.48510 = 0.01111100 · · · . Normally,
the conversion in such cases is done until the required number of decimal places
is obtained. To four decimal places, we can write that 0.48510 = 0.01112 , to eight
PSfragdecimal places: 0.48510 = 0.01111100, and so on.
replacements
This is base 8 system, and it uses the eight digits 0, 1, 2, 3, 4, 5, 6 and 7. The
weighting factors are shown in Figure 1.3.
octal point
The decimal equivalent of the octal number an an−1 · · · a1 a0 .a−1 a−2 · · · a−m is given by:
Example:
page 8 of 101
5
8 459
8 57 R3
8 07 R1
00 R7
The octal number is read in the direction shown by the arrow (upwards). In
this case, we can see that 45910 = 7138 .
Fractions In this case we use repeated (or successive) multiplication by 8. The table
below shows this procedure to convert 0.7812510 to octal.
DECIMAL OCTAL
0.78125 × 8 = 6.25
6.25 − 6 = 0.25 6
0.25 × 8 = 2.00
2−2 = 0 2
The procedure here is to convert each octal digit to its 3-bit binary equivalent then to
juxtapose these codes to give us the equivalent binary code. The 3-bit binary codes
corresponding to the octal digits are shown on the table below:
OCTAL BINARY
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
page 9 of 101
6
As an example, suppose we would like to convert 713.628 to binary. From the above
table, we can see that the 3-bit binary codes for 7, 1, 3, 6 and 2 are respectively 111,
001, 011, 110 and 010. We can therefore directly write that 713.628 = 111001011.1100102.
In this case, we divide the binary number in groups of 3 bits, starting from the binary
point. We then use the table shown in the previous section to get the corresponding
octal digits. As an example, suppose we want to convert 10111101.11112 to octal. The
procedure is illustrated on Figure 1.5.
2 7 5 7 4
page 10 of 101
7
hexadecimal point
The decimal equivalent of the hexadecimal number an an−1 · · · a1 a0 .a−1 a−2 · · · a−m is
given by:
Example:
Integers For integers, we use repeated (successive) division by 16. Note that when
a remainder exceeds 9, we replace it with the corresponding hexadecimal digit
as shown in the above table. The example shown on Figure 1.7 shows how to
apply this method to convert 42810 to hexadecimal.
The hexadecimal number is read in the direction shown by the arrow (upwards).
In this case, we can see that 42810 = 1AC16 .
page 11 of 101
8
PSfrag replacements
16 428
16 26 R 12
16 01 R 10
00 R1
Fractions In this case we use repeated (or successive) multiplication by 16. The
table below shows this procedure in converting 0.7539062510 .
DECIMAL HEXADECIMAL
0.75390625 × 16 = 12.0625
12.0625 − 12 = 0.0625 12 = C
0.0625 × 16 = 1.00
1−1=0 1
The procedure is similar to that of Octal to Binary conversion, the only difference
being that we first convert each hexadecimal digit into 4-bit binary. The 4-bit binary
codes representing each hexadecimal digit are tabulated at the beginning of this
section.
As an example, suppose we want to convert 2EA.B16 to binary. From the above table,
we can see that the 4-bit binary codes for 2, E, A, and B are respectively 0010, 1110,
1010 and 1011 so we can therefore directly write that 2EA16 = 001011101010.10112.
In this case, we divide the binary number in groups of 4 bits, starting from the bi-
nary point. We then use the table shown at the beginning of this section to get
the corresponding hexadecimal digits. As an example, suppose we want to convert
110110011.010112 to octal. The procedure is illustrated on Figure 1.8 below.
Hence 110110011.010112 = 1B3.5816 .
page 12 of 101
9
1 B 3 5 8
Our discussion so far has assumed that we are dealing with positive numbers. The
binary numbers discussed so far are known as unsigned binary numbers.
Digital systems represent all information with binary digits (bits 0,1). Since digital
computers and calculators handle negative as well as positive numbers, some means
is required for representing the sign of the number (+ or -). This is done by the use
of a sign bit. The most significant bit of a binary number is used to denote the sign
of the number.
There are three notations that are commonly used representing signed numbers.
These are:
i) Sign-Magnitude Notation
In all these notations, positive numbers have the Most Significant Bit (MSB) as zero,
while negative numbers have an MSB of 1.
To obtain the sign-magnitude notation of a given number, we first obtain its unsigned
binary equivalent using the methods described in the previous sections. If the num-
ber is positive, we then add a zero (0) to become the MSB, and if the number is
negative, we add a one (1) to become the MSB.
Example
Convert+53 and -53 to binary in sign-magnitude notation.
page 13 of 101
10
Solution:
The unsigned binary code for 53 can be obtained by successive division by 2 as
110101. For +53, we add a ‘0’ sign bit as MSB to give the binary sign-magnitude
code for +53 as 0110101. For -53, we add a ‘1’ for a sign bit to get 1110101. We can
tabulate the decimal equivalents of the 4-bit binary codes, assuming these codes are
in sign-magnitude notation, as shown below:
Sign-Magnitude Code Decimal
0000 +0
0001 +1
0010 +2
0011 +3
0100 +4
0101 +5
0110 +6
0111 +7
1000 -0
1001 -1
1010 -2
1011 -3
1100 -4
1101 -5
1110 -6
1111 -7
Generally, for N bits, the range of integers which can be represented using this nota-
tion = − 2(N −1) − 1 ≤ I ≤ 2(N −1) − 1 .
However, as you can see from the above table, this notation has two distinct patterns
for zero, a positive zero and a negative zero. This creates complications in arithmetic
operations, and for this reason, this notation is not commonly used.
To get the ones complement notation for a positive number, the unsigned binary
notation of the number is obtained, after which the a zero (0) is added to the number
as the MSB (This is similar to the Sign-Magnitude notation).
The ones complement notation of a negative number is obtained from the corre-
sponding positive binary number by changing each zero in the digit to a 1, and each
1 in the positive binary number to a zero. As an example, we saw in the previous sec-
tion that 53 = 110101 in unsigned binary. +53 would be represented by 0110101 in
Ones Complement Notation (OCN). To represent -53 in OCN, we simply complement
all the bits in +53 to get 1001010. We can have a table similar to one in the previous
section, this time assuming the binary codes are in the Ones Complement Notation.
page 14 of 101
11
Generally, for N bits, the range of integers which can be represented using this nota-
tion = − 2(N −1) − 1 ≤ I ≤ 2(N −1) − 1 .
Just as in the previous case, you can see from the above table that this notation also
has two distinct patterns for zero, a positive zero and a negative zero.
To illustrate the problem created by the two patterns for zero, suppose we want to
perform the operation (7−4). This can be rewritten as 7+(−4). From the above table,
+7 = 0111 and −4 = 1011. Adding these two codes gives 10010. Since we are dealing
with 4-bit binary in this case, we can ignore the fifth bit to get 0010. From the above
table once again, we see that 0010 corresponds to +2. But we know that 7 − 4 = +3.
The incorrect result obtained above is as a result of having two zeros. Generally, the
presence of two distinct patterns for zero complicates arithmetic operations and for
this reason, this notation is not commonly used.
The procedure for obtaining the Twos Complement Notation (TCN) of a positive
number is similar to that of obtaining OCN for a positive number. For a negative
number, you add 1 to the Least Significant Bit (LSB) position of the ones complement
notation of the number.
Example
Obtain the TCN of +53 and -53.
Solution:
53 = 110101 in unsigned binary. Adding a sign bit gives +53 = 0110101 in TCN.
To obtain the code for -53, we first obtain the ones complement notation of the code
0110101, which is 1001010. We then add 1 to the LSB position to get 1001011,
which is the TCN of -53.
The decimal equivalent of the TCN binary code an an−1 · · · a1 a0 .a−1 a−2 · · · a−m is given
page 15 of 101
12
by:
A table showing 4-bit TCN codes and their decimal equivalents is shown below:
Twos Complement Decimal
0000 +0
0001 +1
0010 +2
0011 +3
0100 +4
0101 +5
0110 +6
0111 +7
1000 -8
1001 -7
1010 -6
1011 -5
1100 -4
1101 -3
1110 -2
1111 -1
Generally, for N bits, the range of integers which can be represented using this nota-
tion = −2(N −1) ≤ I ≤ 2(N −1) − 1.
In this case, there is only one zero, so there are no problems with arithmetic. In
fact, digital computers use twos complement binary in arithmetic operations since
addition can be carried out just as addition (e.g. 7 − 4 = 7 + (−4). This means that
the same circuit can be used for both addition and subtraction, which saves on the
hardware to be used for these operations.
Example
Convert -29.625 into Twos Complement Binary.
Solution:
29.625 = 1 1 1 0 1 . 1 0 1 (unsigned)
+29.625 = 0 1 1 1 0 1 . 1 0 1 (signed)
-29.625 = 1 0 0 0 1 0 . 0 1 0 (OCN)
+ 1
-29.625 = 1 0 0 0 1 0 . 0 1 1 (TCN)
Hence the Twos Complement notation for -29.625 = 100010.011. As a cross-check,
using the formula for converting a TCN number to decimal, we get:
(−25 ×1)+(24 ×0)+(23 ×0)+(22 ×0)+(21 ×1)+(20 ×0)+(2−1 ×1)+(2−2 ×0)+(2−3 ×1)
page 16 of 101
13
29.625 = 1 1 1 0 1 . 1 0 1 (unsigned)
+29.625 = 0 0 0 0 0 0 0 0 1 1 1 0 1 . 1 0 1 (signed)
-29.625 = 1 1 1 1 1 1 1 1 0 0 0 1 0 . 0 1 0 (OCN)
+ 1
-29.625 = 1 1 1 1 1 1 1 1 0 0 0 1 0 . 0 1 1 (TCN)
As we can see, after obtaining the unsigned binary, we add leading zeros and a ‘0’
sign-bit to make 16 bits then we proceed as usual. Use the formula for TCN to
decimal conversion to show that the result obtained, 1111111100010.011 is equal
to -29.625.
BCD code represents each digit of a decimal number by a 4-bit binary number. The
codes used are tabulated below:
DECIMAL BCD
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
Note that BCD code uses binary codes 0000 to 1001 to represent decimal digits, it
does not use codes 1010, 1011, 1100, 1101, 1110 and 1111. It is a weighted code.
The weightings for a 12-bit BCD number are shown below:
To convert a decimal number to BCD code, we simply write out the BCD code for
each digit e.g. to convert the decimal number 137 to BCD, we can see from the
above table that the BCD code for 1 is 0001, for 3 is 0011 and for 7 is 0111, so the
BCD code for 137 is 000100110111.
To convert a BCD code number to decimal, we simply group the bits in groups of 4
bits each and write out the decimal digit corresponding to each decimal digit.
page 17 of 101
14
The main advantage of BCD code is the relative ease of converting to and from dec-
imal. BCD code is used in digital machines whenever decimal information is either
applied as inputs or displayed as outputs e.g. digital voltmeters, digital clocks, e.t.c.
use BCD because they display information in decimal. Electronic calculators use BCD
because the input numbers are entered in decimal via the keypad and the output
numbers displayed in decimal.
However, BCD code is not used in modern high-speed digital computers because:
• The arithmetic with BCD is more complicated (can you explain these points??)
The excess-3 code (also known as Xs-3 code) for a decimal number is obtained in the
same manner as for BCD, except that 3 is added to each digit before encoding it in
binary. The example below shows how to convert 59 to Xs-3 code.
5 9
+ 3 + 3
—— ——
8 12
↓ ↓
1000 1100
The Xs-3 code for 59 is therefore 10001100. The table below shows the codes used
by Xs-3 code, and these are listed alongside BCD codes.
DECIMAL BCD Xs-3 CODE
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
The Xs-3 code does not use codes 0000, 0001, 0010, 1101, 1110 and 1111.
The advantage of this code is that at least one 1 is present in all codes, providing an
error-detection ability.
page 18 of 101
15
In gray code, only one bit changes in going from one number to the next. It is a non-
weighted code - bit positions in the code do not have any specific weights attached
to them.
ii) Add the binary MSB to the next bit position, record the sum and neglect any
carries.
Applying this procedure on the binary code 101110110, we get the equivalent Gray
Code to be 111001101.
ii) Add the binary MSB to the next significant bit position of the Gray Code num-
ber, again recording the sum and ignoring any carries.
page 19 of 101
16
Observe that only one bit position changes in the binary code in moving from one
number to the next. Gray code is often used in situations where other codes might
produce erroneous or ambiguous results during those transitions in which more than
1 bit of the code is changing e.g. in the transition from 7 to 8 in binary, all bit
positions change, and in a practical circuit, these bit positions may not change at
exactly the same time and this could cause problems in some circuits.
page 20 of 101