0% found this document useful (0 votes)
29 views29 pages

EEC2102-Week 5-Lecture-Chapter-4-1

Uploaded by

arnoldkiptoo545
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)
29 views29 pages

EEC2102-Week 5-Lecture-Chapter-4-1

Uploaded by

arnoldkiptoo545
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/ 29

JOMO KENYATTA UNIVERSITY OF AGRICULTURE AND

TECHNOLOGY

EEC 2102 COMPUTER SYSTEMS


Prepared By:
Dr. Linus Aloo, PhD
E-mail: [email protected]
Phone: 0754188380
References
1. Roger Tokheim, “Digital Electronics, Principles and
Applications”, 8th Edition, McGraw-Hill International Edition, 2014
2. Anil K. M., (2007) Digital Electronics: Principles, Devices and
Applications, John Wiley & Sons, Ltd.
3. Learn Digital Electronics Devices with Arduino: A Practical
Hardware and Software Perspective for Online, Offline, Mobile
and Electronic Learning by OMAE OTERI (Author), Eng. Julius
Weru (Editor), Linus Aloo (Editor).

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 1


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
Chapter Objectives:
At the end of this sub-unit module, students should be able to:

 Understand the fundamentals of numerical data representation and manipulation in digital


computers.

 Explain the rationale for using binary and hexadecimal notation,

 Master the skill of converting between various radix systems e.g converting between decimal and
binary number systems,

 Explain two’s complement representation.

 Understand how errors can occur in computations because of overflow and truncation.

 Understand Binary Codes.

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 2


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.1. Introduction
 The study of number systems is important to enable us understand how data are represented
before they can be processed by any digital computer.
 A bit is the most basic unit of information in a computer.
 It is a state of “on” or “off” (“high” or “low” voltage ) in a digital circuit.
 A byte is a group of eight bits.
 A byte is the smallest possible addressable unit of computer storage.
 The term, “addressable,” means that a particular byte can be retrieved according to its
location in memory.
 A word is a contiguous group of bytes.
 Words can be any number of bits or bytes e.g. 16, 32, or 64 bits are most common.
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 3
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.1. Introduction

 In a word-addressable system, a word is the smallest addressable unit of storage.


 A group of four bits is called a nibble.
 Bytes, therefore, consist of two nibbles: a “high-order nibble,” and a “low-order”
nibble.
4.2 Positional Numbering Systems
 Bytes store numbers using the position of each bit to represent a power of 4.
 The binary system is also called the base-2 system.
 Our decimal system is the base-10 system. It uses powers of 10 for each position in a number.
 Any integer quantity can be represented exactly using any base (or radix).

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 4


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.2 Positional Numbering Systems
 The binary number 11001 in powers of 2 is:
 The decimal number 947 in powers
of 10 is: 1  24+ 1  23 + 0  22 + 0  21 + 1  20
9  10 2 + 4  10 1 + 7  10 0 = 16 + 8 + 0 + 0 + 1 = 25
 When the radix of a number is something
 The decimal number 5836.47 in other than 10, the base is denoted by a
powers of 10 is: subscript.
5  10 3 + 8  10 2 + 3  10 1 + 6  10 0  Sometimes, the subscript 10 is added for
+ 4  10 -1 + 7  10 -2 emphasis:
110012 = 2510

4.3. Types of Number Systems


 There are three main types of number systems: decimal, binary and hexadecimal.
 In any number, the leftmost digit is referred to as the most significant digit, because it carries the highest value.
 The rightmost digit is called the least significant digit.

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 5


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.3.1. Binary Number System

 All numbers in the binary system are represented to base 2, in terms of ‘0’ and ‘1’.
 Starting from the binary point, the place values of different digits in a mixed binary
number are 20 , 21 , 22 and so on (for the integer part) and 2−1 , 2−2 , 2−3 and so on (for
the fractional part).
Example 4.1
Obtain the decimal equivalent of the following mixed binary number: 1001.101
Solution
1001.101 = 𝟐𝟑 × 𝟏 + 𝟐𝟐 × 𝟎 + 𝟐𝟏 × 𝟎 + 𝟐𝟎 × 𝟏 + 𝟐−𝟏 × 𝟏 + 𝟐−𝟐 × 𝟎 + 𝟐−𝟑 × 𝟏
= 𝟐𝟑 + 𝟐𝟎 + 𝟐−𝟏 + 𝟐−𝟑 = 𝟖 + 𝟏 + 𝟎. 𝟓 + 𝟎. 𝟏𝟐𝟓 = 𝟗. 𝟔𝟐𝟓𝟏𝟎
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 6
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.3.1. Binary Number System
Advantages of Binary Number System
1. Logic operations on modern digital computers can be conveniently done in
binary number system.
2. All kinds of data could be conveniently represented in terms of 0’s and 1’s.
3. Basic electronic devices used for hardware implementation can be conveniently
and efficiently operated in two distinctly different modes.
4. The circuits required for performing arithmetic operations such as addition,
subtraction, multiplication, division, etc., become a simple affair in the binary
number system.

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 7


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.3.4. Hexadecimal Number System Table 4.1 Decimal, Binary, and Hexadecimal

 The binary numbering system is the most important radix system for digital Decimal Binary Hexadecimal Octal
computers. 0 00000 0 0
 However, it is difficult to read long strings of binary numbers -- and even a 1 0001 1 1
modestly-sized decimal number becomes a very long binary number. 2 0010 2 2
3 0011 3 3
 For example: 110101000110112 = 1359510 4 0100 4 4
 For compactness and ease of reading, binary values are usually 5 0101 5 5
6 0110 6 6
expressed using the hexadecimal, or base-16, numbering system.
7 0111 7 7
8 1000 8 10
 A sequence of hexadecimal digits can be thought of as 9 1001 9 11
10 1010 A 12
representing an integer in base 16 (Table 4.1). 11 1011 B 13
 Binary digits are grouped into sets of four bits, called a 12 1100 C 14
13 1101 D 15
nibble. 14 1110 E 16
15 1111 F 17
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 8
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.3.4. Hexadecimal Number System

Example 4.2
To illustrate this last point, consider the binary string 110111100001. Obtain its
hexadecimal equivalent.
Solution
First, group the binary string into groups of 4 binary digits each.
𝟏𝟏𝟎𝟏 𝟏𝟏𝟏𝟎 𝟎𝟎𝟎𝟏 = 𝑫𝑬𝟏 𝟏𝟔
D E 1
Similarly, the contents of the memory when represented in hexadecimal form
are very convenient to handle.
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 9
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.4. Converting Between Bases

Converting 190 to base 2 Converting 0.8125 to binary . . .


19010 = 101111102 You are finished when the product is
2 190
zero, or until you have reached the
2 95 0
desired number of binary places.
2 47 1
2 23 1 Our result, reading from top to

2 11 1 bottom is:

2 5 1 0.812510 = 0.11012
2 2 1 This method also works with any
2 1 0 base. Just use the target radix as the
0 1 multiplier.
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 10
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.4. Converting Between Bases

 Using groups of hextets, the binary number 110101000110112 (= 1359510) in hexadecimal is:

If the number of bits is not a


multiple of 4, pad on the left
with zeros.

 Octal (base 8) values are derived from binary by using groups of three bits (8 = 23):

 Octal was very useful when computers used six-bit words.

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 11


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.5. Computer Arithmetic
4.5.1. The Arithmetic and Logic Unit
 Figure 4.1 indicates, in general terms, how the ALU is
interconnected with the rest of the processor.
 Operands for arithmetic and logic operations are
presented to the ALU in registers, and the results of an
operation are stored in registers.
 The ALU may also set flags as the result of an
operation.
 For example, an overflow flag is set to 1 if the result of
a computation exceeds the length of the register into
which it is to be stored. Figure 4.1 ALU Inputs and Outputs

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 12


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.5. Computer Arithmetic
4.5.4. Signed Integer Representation
 The conversions we have so far presented have involved only unsigned numbers.
 To represent signed integers, computer systems allocate the high-order bit to indicate the sign of
a number.
 The high-order bit is the leftmost bit. It is also called the most significant bit.
 0 is used to indicate a positive number; 1 indicates a negative number.
 The remaining bits contain the value of the number (but this can be interpreted different ways).
 There are three ways in which signed binary integers may be expressed:
 Signed magnitude
 One’s complement
 Two’s complement

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 13


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.5. Computer Arithmetic
4.5.4. Signed Integer Representation

 In an 8-bit word, signed magnitude representation places the absolute value of the number in the
7 bits to the right of the sign bit.
 For example, in 8-bit signed magnitude representation:

+3 is: 00000011

- 3 is: 10000011

 Computers perform arithmetic operations on signed magnitude numbers in much the same way
as humans carry out pencil and paper arithmetic.

 Humans often ignore the signs of the operands while performing a calculation, applying the
appropriate sign after the calculation is complete.
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 14
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.5. Computer Arithmetic
4.5.4. Signed Integer Representation Example 4.3: Using signed magnitude

binary arithmetic, find the sum of 75


 Binary addition is as easy as it gets. You
and 46.
need to know only four rules:
0+0= 0 0+1= 1 First, convert 75 and 46 to binary, and arrange

1+0= 1 1 + 1 = 10 as a sum, but separate the (positive) sign bits


from the magnitude bits.
 The simplicity of this system makes it
possible for digital circuits to carry out
arithmetic operations.

Let’s see how the addition rules work with


signed magnitude numbers . . .
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 15
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC

4.5. Computer Arithmetic  With one’s complement addition, the carry


4.5.4. Signed Integer Representation
bit is “carried around” and added to the sum.
 Signed magnitude representation is easy for Example 4.4: Using one’s complement
people to understand, but it requires binary arithmetic, find the sum of 48 and -
complicated computer hardware. 19

 Another disadvantage of signed magnitude is


that it allows two different representations for
zero: positive zero and negative zero.

 For these reasons (among others) computers


systems employ complement systems for We note that 19 in binary is 00010011,
so -19 in one’s complement is: 11101100.
numeric value representation.

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 16


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.5. Computer Arithmetic
4.5.3. 1’s and 2’s Complement for Integer Representation
 The 1’s complement of a binary number is obtained by complementing all its bits, i.e. by replacing 0s with 1s
and 1s with 0s.
 For example, the 1’s complement of (10010110)2 is (01101001)4.
 In the 1’s complement format, the positive numbers remain unchanged. The negative numbers are obtained
by taking the 1’s complement of the positive counterparts.
 For example, +9 will be represented as 00001001 in eight-bit notation, and −9 will be represented as 11110110,
which is the 1’s complement of 00001001.
 Although the “end carry around” adds some complexity, one’s complement is simpler to implement than
signed magnitude.
 But it still has the disadvantage of having two different representations for zero: positive zero and negative
zero.
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 17
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.5. Computer Arithmetic
4.5.3. 1’s and 2’s Complement for Integer Representation
 Two’s complement solves this problem
 The 2’s complement of a binary number is obtained by adding ‘1’ to its 1’s complement.
 For instance, the 2’s complement of (10010110)2 is (01101010)4.
 In the 2’s complement representation of binary numbers, the MSB represents the sign, with a ‘0’
used for a plus sign and a ‘1’ used for a minus sign.
 The remaining bits are used for representing magnitude.
 Positive magnitudes are represented in the same way as in the case of sign-bit or 1’s complement
representation.
 Negative magnitudes are represented by the 2’s complement of their positive counterparts. For
example, +9 would be represented as 00001001, and −9 would be written as 11110111
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 18
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.5. Computer Arithmetic
4.5.3. 1’s and 2’s Complement for Integer Representation

Example 4.5
Find the decimal equivalent of the binary number 00001110 which is expressed in the 2’s complement
format:
Solution
The MSB bit is ‘0’, which indicates a plus sign.
The magnitude bits are: 0001110.
The decimal equivalent = 0 × 𝟐𝟎 + 𝟏 × 𝟐𝟏 + 𝟏 × 𝟐𝟐 + 𝟏 × 𝟐𝟑 + 𝟎 × 𝟐𝟒 × 𝟎 × 𝟐𝟓 + 𝟎 × 𝟐𝟔
= 𝟐𝟏 + 𝟐𝟐 + 𝟐𝟑 = 𝟏𝟒𝟏𝟎
Therefore, 00001110 represents +𝟏𝟒

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 19


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.5. Computer Arithmetic
4.5.3. 1’s and 2’s Complement for Integer Representation

Example 4.6
Find the decimal equivalent of the binary number 10001110 which is expressed in the 2’s
complement format.
Solution
The MSB bit is ‘1’, which indicates a minus sign.
The magnitude bits are therefore given by the 2’s complement of 0001110, i.e. 1110010.
The decimal equivalent = 0 × 𝟐𝟎 + 𝟏 × 𝟐𝟏 + 𝟎 × 𝟐𝟐 + 𝟎 × 𝟐𝟑 + 𝟏 × 𝟐𝟒 × 𝟏 × 𝟐𝟓 + 𝟏 × 𝟐𝟔
= 𝟐𝟏 + 𝟐𝟒 + 𝟐𝟓 + 𝟐𝟔 = 𝟐 + 𝟏𝟔 + 𝟑𝟐 + 𝟔𝟒 = 𝟏𝟏𝟒𝟏𝟎
Therefore, 10001110 represents −𝟏𝟏𝟒.

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 20


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.5. Computer Arithmetic: Signed Integer Representation

• Example 4.7:

• Using two’s complement binary arithmetic, find


the sum of 23 and -9.

• We see that there is carry into the sign bit and


carry out. The final result is correct: 23 + (-9) = 14.

Rule for detecting signed two’s complement overflow: When the “carry in” and
the “carry out” of the sign bit differ, overflow has occurred. If the carry into the
sign bit equals the carry out of the sign bit, no overflow has occurred.

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 21


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.6. BINARY CODES

This is a way of representing symbols using binary numbers


Binary code is given by: -
1. Straight Binary Code
-binary representation
A decimal number is converted to its binary equivalent- ex 21=10101
Advantages of Straight Binary Code
Easier to deal with
Disadvantages of Straight Binary Code
Prone to more errors
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 22
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.6. BINARY CODES

4. Binary Coded Decimal (BCD)

-Obtained by converting each individual decimal digit to its

binary equivalent in groups of 4-bits

 Combine the bits to obtain a string of bits

 Only 0-9 can be converted to binary

 10-15 are invalid cases for BCD

 Also referred to as 8421 representation

 Converting from Decimal to BCD:


 From BCD to Dec-10011001012 = 26510
Ex -2310-00100011BCD
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 23
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC

4.6. BINARY CODES

3. Excess-3
2 7
• -Obtained by adding 3 to each decimal digit and converting to3 binary
3 in groups of 4-bits
5 10 convert to binary = 0101 1010
• Combine them to form a string of bits-
2710 = 01011010Excess-3
4. Gray Code
• -This represents the numbers in a way that each consecutive number will differ by 1 in binary form
Converting from Binary to Gray Code
• Steps
• Most Significant Bit (MSB) remains the same
• 2nd bit is obtained by adding the MSB bit and the 2nd bit of binary then discard the carry
• 3rd bit is obtained by adding 2nd bit to 3rd bit of binary also discard the carry

9/21/2024
• Continue until all the bits are considered. 10112 = 1110gray code
EEC2102 Lecture Notes by Dr. L. A. Aloo 24
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC

4.6. BINARY CODES


4. Gray Code Cont”
• Converting from Gray Code to Binary

• Steps

• Most Significant Bit (MSB) remains the same

• 2nd bit is obtained by adding the MSB bit of the binary to the 2nd bit of gray code then
discard the carry

• Continue until all the bits are considered


1110gray code = 10112

• ASCII Code

• -This is an alpha-numeric code, Represents decimal digits and alphabets in binary and other
symbols
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 25
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
The 7 bit ASCII code
Bit Positions Bit Positions 654
3210
000(0) 001(1) 010(2) 011(3) 100(4) 101(5) 110(6) 111(7)

0000(0) NUL DLE SP 0 @ P ΄ p


0001(1) SOH DC1 ! 1 A Q a q
0010(2) STX DC2 ” 2 B R b r
0011(3) ETX DC3 # 3 C S c s
0100(4) EOT DC4 $ 4 D T d t
0101(5) ENQ NAK % 5 E U e u
0110)6) ACK SYN & 6 F V f v
0111(7) BEL ETB ’ 7 G W g w
1000(8) BS CAN ( 8 H X h x
1001(9) HT EM ) 9 I Y i y
1010(A) LF SUB * : J Z j z
1011(B) VT ESC + ; K [ k {
1100(C) FF FS , < L \ l |
1101(D) CR GS - = M ] m }
1110(E) SO RS . > N ˆ n ~
1111(F) SI US / ? O — o DEL

Example: Letter A = 100 0001


Letter J = 100 1010

Arsenal = 1000001 1110010 1110011 1100101 1101110 1100001 1101100


9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 26
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.7 Floating-Point Representation
Numbers written in scientific notation have
• Floating-point numbers allow an arbitrary three components:
number of decimal places to the right of the
decimal point.

• For example: 0.5  0.25 = 0.125  Computer representation of a floating-point


number consists of three fixed-size fields:
• They are often expressed in scientific notation.

• For example:

0.125 = 1.25  10-1


 This is the standard arrangement of these fields.
5,000,000 = 5.0  106
Note: Although “significand” and “mantissa” do not
technically mean the same thing, many people use these terms
• Computers use a form of scientific notation for
interchangeably. We use the term “significand” to refer to the
floating-point representation. fractional part of a floating point number.

9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 27


CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.7 Floating-Point Representation

 For example, decimal numbers 0.0003754 and 3754 will be represented in floating-point

notation as 3.754 × 10−4 and 3.754 × 103 respectively.

 A hex number 257. ABF will be represented as 4.57ABF × 162 .

 In the case of normalized binary numbers, the leading digit (i.e. the most significant bit),

is always ‘1’ and hence does not require explicit storage.

 The mixed integer number (110.1011)2 will be represented in floating-point notation as

.1101011 × 23 = .1101011𝑒 + 0011. Here, .1101011 is the mantissa and 𝑒 + 0011 implies

that the exponent is +3.


9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 28
CHAPTER 4: NUMBER SYSTEMS AND COMPUTER ARITHMETIC
4.8.Exercises
1. Determine the decimal equivalent of the binary number 𝟏𝟎𝟎𝟏. 𝟎𝟏𝟎𝟏.
Ans. The decimal equivalent of (1001.0101)2 = 9.3125
4. Obtain the decimal equivalent of the hexadecimal number (1E0.2A)16.
Ans. The decimal equivalent of (1E0.2A)16 = (480.164)10
3. Find the binary equivalent of (13.375)10
Ans. The binary equivalent of (13.375)10= (1101.011)2
4. Compute the binary equivalent of (17E.F6)16 and the hex equivalent of (1011001110.011011101)4.
Ans. 17𝐸. 𝐹6 16 = (101111110.1111011) 2 and 1011001110.011011101 2 = (2CE. 6E8) 16
5. (1) Consider the decimal number 2001. Express this in binary, octal, decimal, and hexadecimal form. (2)
Repeat for 2989.
6. Find the decimal equivalent of the binary number 11010111 which is expressed in the 2’s complement
format.
END OF CHAPTER FOUR
9/21/2024 EEC2102 Lecture Notes by Dr. L. A. Aloo 29

You might also like