0% found this document useful (0 votes)
49 views16 pages

Chapter 1 Min

The document discusses number systems and codes used in digital systems. It introduces digital and analog systems, with examples. The four main number systems covered are decimal, binary, octal, and hexadecimal. Conversion methods between these number systems are described, including successive division/multiplication and place value weighting. Binary is the basis for all digital systems. Octal and hexadecimal are used as shorthand for binary.

Uploaded by

Cybertron Badee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views16 pages

Chapter 1 Min

The document discusses number systems and codes used in digital systems. It introduces digital and analog systems, with examples. The four main number systems covered are decimal, binary, octal, and hexadecimal. Conversion methods between these number systems are described, including successive division/multiplication and place value weighting. Binary is the basis for all digital systems. Octal and hexadecimal are used as shorthand for binary.

Uploaded by

Cybertron Badee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Chapter 1

NUMBER SYSTEMS AND CODES

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:

• They are easier to design than analog systems.

• Easy to store large quantities of information.

• Accuracy and precision are greater

• digital circuits are less affected by noise.

1.2 Number Systems

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:

i) Decimal - Used in everyday calculations

page 5 of 101
2

ii) Binary - Used in all digital systems, including digital computers

iii) Octal

iv) Hexadecimal - This number system, along with the Octal system are used as
shorthand notation for the Binary number system.

1.3 Decimal 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

1.4 Binary System

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.

· · · 23 22 21 20 2−1 2−2 2−3 2−4 · · ·

binary point

Figure 1.1: Weighting factors for the binary number system

1.4.1 Binary to Decimal Conversion

The decimal equivalent of the binary number an an−1 · · · a1 a0 .a−1 a−2 · · · a−m is given
by:

(2n × an ) + (2n−1 × an−1 ) + · · · + (21 × a1 ) + (20 × a0 ) + (2−1 × a−1 ) + · · · + (2−m × a−m )

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

1.4.2 Decimal to Binary Conversion

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

Figure 1.2: Example illustrating successive division by 2

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

In this case, the binary number is read downwards, so 0.812510 = 0.11012 .


Note that in some cases, the decimal fraction cannot be represented in a finite
number of bits - in this case, we have to truncate the binary number at some
point e.g. conversion of 0.48510 to binary:

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

1.5 Octal System

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.

· · · 83 82 81 80 8−1 8−2 8−3 8−4 · · ·

octal point

Figure 1.3: Weighting factors for the octal number system

1.5.1 Octal to Decimal Conversion

The decimal equivalent of the octal number an an−1 · · · a1 a0 .a−1 a−2 · · · a−m is given by:

(8n × an ) + (8n−1 × an−1 ) + · · · + (81 × a1 ) + (80 × a0 ) + (8−1 × a−1 ) + · · · + (8−m × a−m )

Example:

125.368 = (82 × 1) + (81 × 2) + (80 × 5) + (8−1 × 3) + (8−2 × 6) = 85.4687510

page 8 of 101
5

1.5.2 Decimal to Octal Conversion

Integers For integers, we use repeated (successive) division by 8. The example


shownPSfrag replacements
on Figure 1.4 shows how to apply this method to convert 45910 to octal.

8 459
8 57 R3
8 07 R1
00 R7

Figure 1.4: Example illustrating successive division by 8

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

In this case, the octal number is read downwards, so 0.7812510 = 0.628 .


Exercise
Show that 0.48510 expressed in octal to six decimal places equals 0.3702438 .

1.5.3 Octal to Binary Conversion

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.

1.5.4 Binary to Octal conversion

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.

Divide into groups


of 3 bits on each
side of binary point
10111101.1111
one zero two zeros
added to added to
make 3 bits make 3 bits
0 1 0 1 1 1 1 0 1. 1 1 1 1 0 0

2 7 5 7 4

Figure 1.5: Binary to octal conversion

Hence 10111101.11112 = 275.748 .


We can see that it is very easy to perform binary to octal operation and vice-versa.

1.6 Hexadecimal Number System

The hexadecimal number system uses 16 digits, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D,


E and F. The table below shows the correlation between these digits and the decimal,
(4-bit) binary and octal systems.

page 10 of 101
7

HEXADECIMAL DECIMAL BINARY OCTAL


0 0 0000 0
1 1 0001 1
2 2 0010 2
3 3 0011 3
4 4 0100 4
5 5 0101 5
6 6 0110 6
7 7 0111 7
8 8 1000 10
9 9 1001 11
PSfrag replacements A 10 1010 12
B 11 1011 13
C 12 1100 14
D 13 1101 15
E 14 1110 16
F 15 1111 17

The weighting factors are shown in Figure 1.6.

··· 163 162 161 160 16−1 16−2 16 16


−3 −4 · · ·

hexadecimal point

Figure 1.6: Weighting factors for the hexadecimal number system

1.6.1 Hexadecimal to Decimal Conversion

The decimal equivalent of the hexadecimal number an an−1 · · · a1 a0 .a−1 a−2 · · · a−m is
given by:

(16n × an ) + · · · + (161 × a1 ) + (160 × a0 ) + (16−1 × a−1 ) + · · · + (16−m × a−m )

Example:

2EA.B16 = (162 × 2) + (161 × 14) + (160 × 10) + (16−1 × 11) = 746.687510

1.6.2 Decimal to Hexadecimal Conversion

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

Figure 1.7: Example illustrating successive division by 16

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

In this case, the hexadecimal number is read downwards, so 0.7539062510 =


0.C116 .
Exercise
Show that 0.48510 expressed in hexadecimal to five decimal places equals 0.7C28F16 .

1.6.3 Hexadecimal to Binary Conversion

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.

1.6.4 Binary to Hexadecimal conversion

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

Divide into groups


of 4 bits on each
side of binary point
110110011.01011
three zeros three zeros
added to added to
make 4 bits make 4 bits
0 0 0 1 1 0 1 1 0 0 1 1 . 0 1 0 1 1 0 0 0

1 B 3 5 8

Figure 1.8: Binary to hexadecimal conversion

1.7 Signed Binary Numbers

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

ii) Ones (1’s) Complement Notation

iii) Twos (2’s) Complement Notation

In all these notations, positive numbers have the Most Significant Bit (MSB) as zero,
while negative numbers have an MSB of 1.

1.7.1 Sign-Magnitude Notation

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.

1.7.2 Ones Complement Notation

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

Ones Complement Decimal


0000 +0
0001 +1
0010 +2
0011 +3
0100 +4
0101 +5
0110 +6
0111 +7
1000 -7
1001 -6
1010 -5
1011 -4
1100 -3
1101 -2
1110 -1
1111 -0

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.

1.7.3 Twos Complement Notation

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:

(−2n × an ) + (2n−1 × an−1 ) + · · · + (21 × a1 ) + (20 × a0 ) + (2−1 × a−1 ) + · · · + (2−m × a−m )

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)

= −32 + 2 + 0.5 + 0.125 = −29.625

In the above example, -29.625 is represented using 9 bits. Suppose we wanted to


represent the number using, say, 16 bits. Then the procedure is shown below:

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.

1.8 Binary Number Codes

These are binary codes which have special applications.

1.8.1 Binary Coded Decimal (BCD) code

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:

800 400 200 100 80 40 20 10 8 4 2 1

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:

• It requires more storage space

• The arithmetic with BCD is more complicated (can you explain these points??)

1.8.2 Excess-3 code

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

1.8.3 Gray Code

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.

Converting from Binary to Gray Code

i) Record the MSB of the binary number.

ii) Add the binary MSB to the next bit position, record the sum and neglect any
carries.

iii) Record successive sums until completed.

Applying this procedure on the binary code 101110110, we get the equivalent Gray
Code to be 111001101.

Converting from Gray to Binary

i) Record the MSB of the Gray Code number.

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.

iii) Continue the process until completed.

This procedure applied to Gray Code number 111001101 yields 101110110.


The table below shows the Gray codes for the first 16 decimal digits.
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

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

You might also like