You are on page 1of 64

1

Democratic and Popular Republic of Algeria


Ministry of Higher Education and Scientific Research
Higher School of Computer Science, May 8, 1945, Sidi Bel Abbes

Academic year: 2023-2024 Semester 1


Preparatory class 1 Module: Computer Architecture 1
2

Introduction

 The organization of any computer depends considerably on how it represents


data.
 This chapter describes the various ways in which computers can store and
manipulate numbers and characters.
 The ideas presented in the following sections form the basis for understanding
the organization and function of all types of digital systems.
3

Bit / Byte

 The most basic unit of information in a digital computer is called a bit, which is
a contraction of binary digit.
 A bit has two numerical values: 0 and 1.
 In the concrete sense, a bit is nothing more than a state of “on” or “off ” (or
“high” and “low”) within a computer circuit.
 In 1964, the designers of the IBM System/360 computer established a
convention of using groups of 8 bits as the basic unit of addressable computer
storage.
 They called this collection of 8 bits a byte.
4

Computer words

 Computer words consist of two or more adjacent bytes that are sometimes
addressed and almost always are manipulated collectively.
 The word size represents the data size that is handled most efficiently by a
particular architecture.
 Words can be 16 bits, 32 bits, 64 bits, or any other size that makes sense in the
context of a computer’s organization (including sizes that are not multiples of
eight).
 An 8-bit byte can be divided into two 4-bit halves called nibbles (or nybbles).
 Because each bit of a byte has a value within a positional numbering system,
the nibble containing the least-valued binary digit is called the low-order
nibble, and the other half the high-order nibble.
5

Digital systems

 Digital systems have such a prominent role in everyday life that we refer to the
present technological period as the digital age.
 Digital systems are used in communication, business transactions, traffic
control, medical treatment, etc.
 We have digital telephones, digital televisions, digital cameras, digital
computers, etc.
 We enjoy music downloaded to our portable media player and other handheld
devices having high-resolution displays and touch-screen graphical user
interfaces (GUIs).
 GUIs enable them to execute commands that appear to the user to be simple,
but which, in fact, involve precise execution of a sequence of complex internal
instructions.
 Most, if not all, of these devices have a special-purpose digital computer, or
processor, embedded within them.
6

Digital systems

 The most striking property of the digital computer is its generality.


 It can follow a sequence of instructions, called a program, which operates on given
data.
 The user can specify and change the program or the data according to the specific
need.
 Because of this flexibility, general-purpose digital computers can perform a variety
of information-processing tasks that range over a wide spectrum of applications
and provide unprecedented access to massive repositories of information and
media.
 One characteristic of digital systems is their ability to represent and manipulate
discrete elements of information.
 Any set that is restricted to a finite number of elements contains discrete
information.
 Examples of discrete sets are the 10 decimal digits, the 26 letters of the alphabet,
the 52 playing cards, and the 64 squares of a chessboard.
 Early digital computers were used for numeric computations. In this case, the
discrete elements were the digits. From this application, the term digital computer
emerged.
7

Digital systems

 Discrete elements of information are represented with groups of bits called


binary codes.
 For example, the decimal digits 0 through 9 are represented in a digital system
with a code of four bits (e.g., the number 7 is represented by 0111).
 How a pattern of bits is interpreted as a number depends on the code system
in which it resides.
 To make this distinction, we could write (0111)2 to indicate that the pattern
0111 is to be interpreted in a binary system, and (0111)10 to indicate that the
reference system is decimal.
 Then (0111)2 = (7)10, which is not the same as (0111)10, or one hundred eleven.
The subscript indicating the base for interpreting a pattern of bits will be used
only when clarification is needed.
 Thus, a digital system is a system that manipulates discrete elements of
information represented internally in binary form.
8

Binary Numbers

 A decimal number such as 7 392 represents a quantity equal to 7 thousands, plus 3


hundreds, plus 9 tens, plus 2 units. The thousands, hundreds, etc., are powers of 10
implied by the position of the coefficients (symbols) in the number. To be more
exact, 7 392 is a shorthand notation for what should be written as:
7 * 103 + 3 * 102 + 9 * 101 + 2 * 100

 However, the convention is to write only the numeric coefficients and, from
their position, deduce the necessary powers of 10, with powers increasing
from right to left. In general, a number with a decimal point is represented by
a series of coefficients: …a5a4a3a2a1a0.a-1a-2a-3...
 The coefficients aj are any of the 10 digits (0, 1, 2, ...,9), and the subscript
value j gives the place value and, hence, the power of 10 by which the
coefficient must be multiplied. Thus, the preceding decimal number can be
expressed as:
…105a5 + 104a4 + 103a3 + 102a2 + 101a1 + 100a0 + 10-1a-1 + 10-2a-2 + 10-3a-3…
with a3 = 7, a2 = 3, a1 = 9, and a0 = 2, and the other coefficients equal to zero.
9

Binary Numbers
 The radix (base) of a number system determines the number of distinct values
that can be used to represent any arbitrary number.
 The decimal number system is said to be of base, or radix, 10 because it uses
10 digits and the coefficients are multiplied by powers of 10.
 The binary system is a different number system. The coefficients of the binary
number system have only two possible values: 0 and 1.
 Each coefficient aj is multiplied by a power of the radix, for example, 2j, and the
results are added to obtain the decimal equivalent of the number.
 The radix point (e.g., the decimal point when 10 is the radix) distinguishes
positive powers of 10 from negative powers of 10.
 For example, the decimal equivalent of the binary number 11010.11 is 26.75,
as shown from the multiplication of the coefficients by powers of 2:
1 * 24 + 1 * 23 + 0 * 22 + 1 * 21 + 0 * 20 + 1 * 2-1 + 1 * 2-2 = 26.75
10

Binary Numbers
 There are many different number systems.
 In general, a number expressed in a base-r system has coefficients multiplied
by powers of r: an * rn + an - 1 * rn - 1 + … + a2 * r2 + a1 * r + a0 + a-1 * r-1 + a-2 * r-2 +
… + a-m * r-m

 The octal number system is a base-8 system that has eight digits: 0, 1, 2, 3, 4, 5,
6, 7.
 An example of an octal number is (127.4)8.
 To determine its equivalent decimal value, we expand the number in a power
series with a base of 8: (127.4)8 = 1 * 82 + 2 * 81 + 7 * 80 + 4 * 8-1 = (87.5)10
 Note that the digits 8 and 9 cannot appear in an octal number.
11

Binary Numbers

 It is customary to borrow the needed r digits for the coefficients from the
decimal system when the base of the number is less than 10.
 The letters of the alphabet are used to supplement the 10 decimal digits when
the base of the number is greater than 10.
 For example, in the hexadecimal (base-16) number system, the first 10 digits
are borrowed from the decimal system.
 The letters A, B, C, D, E, and F are used for the digits 10, 11, 12, 13, 14, and 15,
respectively.
 An example of a hexadecimal number is:
(B65F)16 = 11 * 163 + 6 * 162 + 5 * 161 + 15 * 160 = (46 687)10
12

Binary Numbers
• In computer work, 210 is referred to as K (kilo), 220 as M (mega), 230 as G (giga),
and 240 as T (tera).
• Thus, 4K = 212 = 4 096 and 16M = 224 = 16 777 216.
• Computer memory capacity and word size are usually given in bytes.
• A computer hard disk with four gigabytes of storage has a capacity of 4G = 232
bytes (approximately 4 billion bytes).
• A terabyte is 1024 gigabytes, approximately 1 trillion bytes.
13

Binary Numbers
• Arithmetic operations with numbers in base r follow the same rules as for
decimal numbers.
• When a base other than the familiar base 10 is used, one must be careful to
use only the r-allowable digits.
• Examples of different arithmetic operations on two binary numbers are as
follows:
14

Number-Base Conversions
• Representations of a number in a different radix are said to be equivalent if
they have the same decimal representation.
• For example, (0011)8 and (1001)2 are equivalent—both have decimal value 9.
• The conversion of a number in base r to decimal is done by expanding the
number in a power series and adding all the terms as shown previously.
• We now present a general procedure for the reverse operation of converting a
decimal number to a number in base r.
• If the number includes a radix point, it is necessary to separate the number into
an integer part and a fraction part, since each part must be converted
differently.
• The conversion of a decimal integer to a number in base r is done by dividing
the number and all successive quotients by r and accumulating the remainders.
15

Number-Base Conversions
• Example: To convert decimal 41 to binary. First, 41 is divided by 2 to give an
integer quotient of 20 and a remainder of 1. Then the quotient is again divided
by 2 to give a new quotient and remainder. The process is continued until the
integer quotient becomes 0. The coefficients of the desired binary number are
obtained from the remainders as follows:

• Therefore, the answer is (41)10 = (a5a4a3a2a1a0)2 = (101001)2.


16

Number-Base Conversions
• Example: Convert decimal 153 to octal.
• The required base r is 8.
• First, 153 is divided by 8 to give an integer quotient of 19 and a remainder of 1.
• Then 19 is divided by 8 to give an integer quotient of 2 and a remainder of 3.
• Finally, 2 is divided by 8 to give a quotient of 0 and a remainder of 2.
• This process can be conveniently tabulated as follows:

Integer Remainder
17

Number-Base Conversions
• The conversion of a decimal fraction to binary is accomplished by a method
similar to that used for integers. However, multiplication is used instead of
division, and integers instead of remainders are accumulated.
• Example: Convert (0.6875)10 to binary. First, 0.6875 is multiplied by 2 to give an
integer and a fraction. Then the new fraction is multiplied by 2 to give a new
integer and a new fraction. The process is continued until the fraction becomes
0 or until the number of digits has sufficient accuracy. The coefficients of the
binary number are obtained from the integers as follows:

• Therefore, the answer is (0.6875)10 = (0.a-1 a-2 a-3 a-4)2 = (0.1011)2.


18

Number-Base Conversions
• To convert a decimal fraction to a number expressed in base r, a similar
procedure is used. However, multiplication is by r instead of 2, and the
coefficients found from the integers may range in value from 0 to r - 1 instead
of 0 and 1.
• Example: Convert (0.513)10 to octal.

...

• (0.513)10 = (0.406517…)8
19

Number-Base Conversions
• The conversion of decimal numbers with both integer and fraction parts is done
by converting the integer and the fraction separately and then combining the
two answers:
(41.6875)10 = (101001.1011)2
(153.513)10 = (231.406517)8
20

Octal and Hexadecimal Numbers


• The conversion from and to binary, octal, and hexadecimal plays an important
role in digital computers, because shorter patterns of hex characters are easier
to recognize than long patterns of 1’s and 0’s.
• Since 23 = 8 and 24 = 16, each octal digit corresponds to three binary digits and
each hexadecimal digit corresponds to four binary digits.
21

Octal and Hexadecimal Numbers


22

Octal and Hexadecimal Numbers


• The conversion from binary to octal is easily accomplished by partitioning the
binary number into groups of three digits each, starting from the binary point
and proceeding to the left and to the right.
• The corresponding octal digit is then assigned to each group.
• The following example illustrates the procedure:

• Conversion from binary to hexadecimal is similar, except that the binary


number is divided into groups of four digits:
23

Octal and Hexadecimal Numbers


• Conversion from octal or hexadecimal to binary is done by reversing the
preceding procedure.
• Each octal digit is converted to its three-digit binary equivalent.
• Similarly, each hexadecimal digit is converted to its four-digit binary equivalent.
24

Signed Integer Representation


• Digital systems, such as the computer, must be able to handle both positive and
negative numbers.
• A signed binary number consists of both sign and magnitude information.
• The sign indicates whether a number is positive or negative, and the magnitude
is the value of the number.
• There are different forms in which signed integer numbers can be represented
in binary, such as: sign-magnitude, 1’s complement, and 2’s complement..
25

Signed Magnitude
• The set of positive and negative integers is referred to as the set of signed
integers.
• The problem with representing signed integers as binary values is the sign.
• Signed-magnitude representation is one method of solving this problem.
• As its name implies, a signed-magnitude number has a sign as its leftmost bit
(also referred to as the high-order bit or the most significant bit) whereas the
remaining bits represent the magnitude (or absolute value) of the numeric
value.
• For example, in an 8-bit word, –1 would be represented as 10000001, and +1 as
00000001.
• In a computer system that uses signed-magnitude representation and 8 bits to
store integers, 7 bits can be used for the actual representation of the
magnitude of the number.
• This means that the largest integer an 8-bit word can represent is 27 – 1, or 127
(a zero in the high-order bit, followed by 7 ones).
• The smallest integer is 8 ones, or –127.
• Therefore, N bits can represent –(2(N–1) – 1) to 2(N–1) – 1.
26

Signed Magnitude
• Computers must be able to perform arithmetic calculations on integers that are
represented using this notation.
• Signed-magnitude arithmetic is carried out using essentially the same methods
that humans use with pencil and paper, but it can get confusing very quickly.
• As an example, consider the rules for addition: (1) If the signs are the same,
add the magnitudes and use that same sign for the result; (2) If the signs differ,
you must determine which operand has the larger magnitude. The sign of the
result is the same as the sign of the operand with the larger magnitude, and
the magnitude must be obtained by subtracting (not adding) the smaller one
from the larger one.
• If you consider these rules carefully, this is the method you use for signed
arithmetic by hand.
• We arrange the operands in a certain way based on their signs, perform the
calculation without regard to the signs, and then supply the sign as appropriate
when the calculation is complete.
• When modeling this idea in an 8-bit word, we must be careful to include only 7
bits in the magnitude of the answer, discarding any carries that take place over
the high-order bit.
27

Signed Magnitude
• Example: Add (01001111)2 to (00100011)2 using signed-magnitude arithmetic.

• The arithmetic proceeds just as in decimal addition, including the carries, until
we get to the seventh bit from the right.
• If there is a carry here, we say that we have an overflow condition and the
carry is discarded, resulting in an incorrect sum.
• There is no overflow in this example.
• Sign bits are segregated because they are relevant only after the addition is
complete.
• In this case, we have the sum of two positive numbers, which is positive.
28

Signed Magnitude
• Example: Add (01001111)2 to (01100011)2 using signed-magnitude arithmetic.

• We obtain the erroneous result of 79 + 99 = 50.


29

Signed Magnitude
• Signed magnitude representation has two main disadvantages:
1. Two Representations for Zero: In signed magnitude, both +0 and -0 have
distinct binary representations, which can complicate calculations and
comparisons involving zero.
2. Complex Arithmetic Operations: Arithmetic operations like addition and
subtraction can become more complex due to the need to handle the sign
bit and separate magnitude calculations. This complexity can slow down
computations.
• For these reasons, while signed magnitude representation is conceptually
straightforward and intuitive, it is often not the preferred choice in modern
computing systems, where alternatives like two's complement representation
offer more efficient and versatile ways of handling signed numbers.
30

Complement Systems
• Number theorists have known for hundreds of years that one decimal number
can be subtracted from another by adding the difference of the subtrahend
from all nines and adding back a carry.
• This is called taking the nine’s complement of the subtrahend or, more
formally, finding the diminished radix complement of the subtrahend.
• Let’s say we wanted to find 167 – 52.
• Taking the difference of 52 from 999, we have 947.
• Thus, in nine’s complement arithmetic, we have 167 – 52 = 167 + 947 = 1114.
• The “carry” from the hundreds column is added back to the units place, giving
us a correct 167 – 52 = 115.
• This method was commonly called “casting out 9s” and has been extended to
binary operations to simplify computer arithmetic.
• The advantage that complement systems give us over signed magnitude is that
there is no need to process sign bits separately, but we can still easily check the
sign of a number by looking at its high-order bit.
31

One’s Complement
• As illustrated, given a number N in base r having d digits, the diminished radix
complement of N is defined to be: (rd – 1) – N.
• For binary numbers, r = 2. For example, the one’s complement of (0101)2 is
(1111)2 – (0101) 2 = (1010) 2.
• Although we could tediously borrow and subtract, a few experiments will
convince you that forming the one’s complement of a binary number amounts
to nothing more than switching all of the 1s with 0s and vice versa.
• This sort of bit-flipping is very simple to implement in computer hardware.
32

One’s Complement
• It is important to note at this point that although we can find the nine’s
complement of any decimal number or the one’s complement of any binary
number, we are most interested in using complement notation to represent
negative numbers.
• We know that performing a subtraction, such as 10 – 7, can also be thought of
as “adding the opposite,” as in 10 + (–7).
• Complement notation allows us to simplify subtraction by turning it into
addition, but it also gives us a method to represent negative numbers.
• Because we do not wish to use a special bit to represent the sign (as we did in
signed-magnitude representation), we need to remember that if a number is
negative, we should convert it to its complement.
• The result should have a 1 in the leftmost bit position to indicate that the
number is negative.
33

One’s Complement
• Example: Express 23 and –9 in 8-bit binary, assuming a computer is using one's
complement representation.
34

One’s Complement
• Unlike signed magnitude, in one's complement addition there is no need to
maintain the sign bit separate from the other bits. The sign takes care of itself.
• Example: Add (01001111)2 to (00100011)2 using one’s complement addition.
35

One’s Complement
• Example: Suppose we wish to subtract 9 from 23.
• To carry out a one's complement subtraction, we first express the subtrahend
(9) in one's complement, then add it to the minuend (23).
• The high-order bit will have a 1 or a 0 carry, which is added to the low-order bit
of the sum (this is called end carry-around and results from using the
diminished radix complement).
36

One’s Complement
• Example: Add 9 to –23 using one’s complement arithmetic.

• How do we know that (11110001)2 is actually –14?


• We simply need to take the one’s complement of this binary number
(remembering it must be negative because the leftmost bit is negative).
• The one’s complement of (11110001)2 is (00001110)2, which is 14.

• The primary disadvantage of one's complement is that we still have two


representations for 0: 00000000 and 11111111.
• For this and other reasons, computer engineers long ago stopped using one's
complement in favor of the more efficient two's complement representation
for binary numbers.
37

Two’s Complement
• Two's complement is an example of a radix complement.
• Given a number N in base r having d digits, the radix complement of N is
defined as rd – N for N ≠ 0 and 0 for N = 0.
• For example, in binary, the two's complement of the 4-bit number (0011)2 is:
24 – (0011)2 = (10000)2 – (0011)2 = (1101)2
• Upon closer examination, you will discover that two's complement is nothing
more than one's complement incremented by 1.
• To find the two's complement of a binary number, simply flip bits and add 1.
This simplifies addition and subtraction as well.
• Because the subtrahend (the number we complement and add) is incremented
at the outset, there is no end carry-around to worry about.
• We simply discard any carries involving the high-order bits.
• As before, positive numbers can be left alone; we only need to complement
negative numbers to get them into their two's complement form.
38

Two’s Complement
• Example: Express 23, –23, and –9 in 8-bit binary, assuming a computer is using
two's complement representation.
39

Two’s Complement
• Because the representation of positive numbers is the same in one's
complement and two's complement (as well as signed-magnitude), the process
of adding two positive binary numbers is the same.
• Example: Add (01001111)2 to (00100011)2 using two's complement addition.
40

Two’s Complement
• Suppose we are given the binary representation for a number and want to
know its decimal equivalent.
• Positive numbers are easy. For example, to convert the two's complement
value of (00010111)2 to decimal, we simply convert this binary number to a
decimal number to get 23.
• However, converting two's complement negative numbers requires a reverse
procedure similar to the conversion from decimal to binary.
• Suppose we are given the two's complement binary value of (11110111)2, and
we want to know the decimal equivalent.
• We know this is a negative number but must remember it is represented using
two's complement.
• We first flip the bits and then add 1 (find the one's complement and add 1).
• This results in the following: 00001000 + 1 = 00001001.
• This is equivalent to the decimal value 9.
• However, the original number we started with was negative, so we end up with
–9 as the decimal equivalent to (11110111)2.
41

Two’s Complement
• Example: Add 9 to –23 using two’s complement arithmetic.

• Example: Find the sum of 23 and –9 in binary using two’s complement


arithmetic.
42

Two’s Complement
• Example: Find the sum of -23 (11101001)2 and -9 (11110111)2 using two's
complement addition.

• Notice that the discarded carries did not cause an erroneous result.
• An overflow occurs if two positive numbers are added and the result is
negative, or if two negative numbers are added and the result is positive.
• It is not possible to have overflow when using two's complement notation if a
positive and a negative number are being added together.
43

Two’s Complement
• A Simple Rule for Detecting an Overflow Condition in Signed Numbers: If the
carry into the sign bit equals the carry out of the bit, no overflow has occurred.
If the carry into the sign bit is different from the carry out of the sign bit,
overflow (and thus an error) has occurred.

• The following example indicates overflow because the carry into the sign bit (a
1 is carried in) is not equal to the carry out of the sign bit (a 0 is carried out).
• Example: Find the sum of 126 and 8 in binary using two's complement
arithmetic.
44

Two’s Complement
• Two's complement is the most popular choice for representing signed numbers. The
algorithm for adding and subtracting is quite easy, has the best representation for 0
(all 0 bits), and is easily extended to larger numbers of bits.
• The biggest drawback is in the asymmetry seen in the range of values that can be
represented by N bits.
• With signed-magnitude numbers, for example, 4 bits allow us to represent the
values –7 through +7.
• However, using two's complement, we can represent the values –8 through +7,
which is often confusing to anyone learning about complement representations.
• To see why +7 is the largest number we can represent using 4-bit two's complement
representation, we need only remember that the first bit must be 0. If the
remaining bits are all 1s (giving us the largest magnitude possible), we have (0111)2,
which is 7.
• An immediate reaction to this is that the smallest negative number should then be
(1111)2, but we can see that (1111)2 is actually –1 (flip the bits, add one, and make
the number negative).
• So how do we represent –8 in two's complement notation using 4 bits? It is
represented as (1000)2. We know this is a negative number. If we flip the bits
(0111), add 1 (to get 1000, which is 8), and make it negative, we get –8.
45

Excess-M Representation for Signed Numbers


• Excess-M representation (also called offset binary representation) uses
unsigned binary values to represent signed integers.
• However, excess-M representation, unlike signed magnitude and the
complement encodings, is more intuitive because the binary string with all 0s
represents the smallest number, whereas the binary string with all 1s
represents the largest value; in other words, ordering is preserved.
• The unsigned binary representation for integer M (called the bias) represents
the value 0, whereas all zeros in the bit pattern represents the integer –M.
• Essentially, a decimal integer is “mapped” to an unsigned binary integer, but
interpreted as positive or negative depending on where it falls in the range.
• If we are using n bits for the binary representation, we need to select the bias
in such a manner that we split the range equally.
• We typically do this by choosing a bias of 2n–1 – 1.
• For example, if we were using 4-bit representation, the bias should be 24–1 – 1 =
7.
• Just as with signed magnitude, one's complement, and two's complement,
there is a specific range of values that can be expressed in n bits.
46

Excess-M Representation for Signed Numbers


• The unsigned binary value for a signed integer using excess-M representation is
determined simply by adding M to that integer.
• For example, assuming that we are using excess-7 representation:
 the integer 0 would be represented as 0 + 7 = 7 = (0111)2;
 the integer 3 would be represented as 3 + 7 = 10 = (1010)2;
 and the integer –7 would be represented as –7 + 7 = 0 = (0000)2.

• Using excess-7 notation and given the binary number (1111)2, to find the
decimal value it represents, we simply subtract 7: (1111)2 = 15, and 15 – 7 = 8;
therefore, the value (1111)2, using excess-7 representation, is +8.
47

Fixed and Floating-Point Representation


• This section introduces fixed- and floating-point number systems that can
represent rational numbers.
• Fixed-point numbers are analogous to decimals; some of the bits represent the
integer part, and the rest represent the fraction.
• Floating-point numbers are analogous to scientific notation, with a mantissa
and an exponent.
48

Fixed-Point Number Systems


• Fixed-point notation has an implied binary point between the integer and
fraction bits, analogous to the decimal point between the integer and fraction
digits of an ordinary decimal number.
• For example, Figure (a) shows a fixed-point number with four integer bits and
four fraction bits. Figure (b) shows the implied binary point, and Figure (c)
shows the equivalent decimal value.
• The integer bits are called the high word and the fraction bits are called the
low word.
49

Fixed-Point Number Systems


• Signed fixed-point numbers can use two's complement, sign/magnitude
notation, etc.
• The figure below shows the fixed-point representation of −2.375 using both
notations with four integer and four fraction bits.
• In sign/magnitude form, the most significant bit is used to indicate the sign.
• The two's complement representation is formed by inverting the bits of the
absolute value and adding a 1 to the least significant (rightmost) bit. In this
case, the least significant bit position is in the 2−4 column.

Fixed-point representation of −2.375: (a) absolute value, (b) sign and magnitude,
(c) two's complement
50

Fixed-Point Number Systems


• Example (Arithmetic With Fixed-point Numbers): Compute 0.75 + −0.625 using
fixed-point numbers.
• (0.625)10 = (0000.1010)2
• Use two's complement representation for signed numbers so that addition
works correctly. The conversion of −0.625 to fixed-point two's complement
notation is done as follows:

• The fixed-point binary addition is done as follows:

• Note that the leading 1 in the binary fixed-point addition is discarded from the
8-bit result.
51

Floating-Point Representation
• Floating-point numbers are analogous to scientific notation.
• They circumvent the limitation of having a constant number of integer and
fraction bits, allowing the representation of very large and very small numbers.
• Floating-point numbers consist of three parts: ± M × BE
 a sign bit,
 an exponent (E) part (representing the exponent on a power of 2),
 and a fractional part (mantissa (M) or significand)

• For example, 32 bits can be used to represent 1 sign bit, 8 exponent bits, and
23 mantissa bits.
52

Floating-Point Representation
• Example: Show the floating-point representation of the decimal number 228.
• Solution: First convert the decimal number into binary:
(228)10 = (11100100)2 = (1.11001)2 × 27
• The following Figure shows the 32-bit encoding, which will be modified later for
efficiency. The sign bit is positive (0), the 8 exponent bits give the value 7, and
the remaining 23 bits are the mantissa:

• In binary floating-point, the first bit of the mantissa (to the left of the binary
point) is always 1 and therefore need not be stored. It is called the implicit
leading one. The following Figure shows the modified floating-point
representation of 228. The implicit leading one is not included in the 23-bit
mantissa for efficiency. Only the fraction bits are stored. This frees up an extra
bit for useful data:
53

Floating-Point Representation
• We make one final modification to the exponent field.
• The exponent needs to represent both positive and negative exponents.
• To do so, floating-point uses a biased exponent, which is the original exponent
plus a constant bias.
• 32-bit floating-point uses a bias of 127 = 28-1 - 1.
• For example, for the exponent 7, the biased exponent is 7 + 127 = 134 =
(10000110)2. For the exponent −4, the biased exponent is: −4 + 127 = 123 =
(01111011)2.
• The following Figure shows (1.11001)2 × 27 represented in floating-point
notation with an implicit leading one and a biased exponent of 134 (7 + 127).
This notation conforms to the IEEE 754 floating-point standard.
54

Floating-Point Representation
 Special Cases: 0, ±∞, and NaN: The IEEE floating-point standard has special cases to
represent numbers such as zero, infinity, and illegal results.
• For example, representing the number zero is problematic in floating-point notation
because of the implicit leading one.
• Special codes with exponents of all 0's or all l's are reserved for these special cases.
NaN is used for numbers that don't exist, such as √-1:

X Sign bit can be either 0 or 1.


55

Floating-Point Representation
 Single- and Double-Precision Formats: So far, we have examined 32-bit
floating-point numbers. This format is also called single-precision, single, or
float.
 The IEEE 754 standard also defines 64-bit double-precision numbers (also
called double) that provide greater precision and greater range:
56

Character Codes
• We have seen how digital computers use the binary system to represent and
manipulate numeric values.
• We have yet to consider how these internal values can be converted to a form
that is meaningful to humans.
• The manner in which this is done depends on both the coding system used by
the computer and how the values are stored and retrieved.
57

Binary-Coded Decimal (BCD)


• For many applications, we need the exact binary equivalent of the decimal
system, which means we need an encoding for individual decimal digits.
• This is precisely the case in many business applications that deal with money.
• BCD is another process for converting decimal numbers into their binary
counterparts and is very common in electronics, particularly those that display
numerical data, such as alarm clocks and calculators.
• BCD encodes each digit of a decimal number into a 4-bit binary form.
• For example, to encode 146, the decimal digits are replaced by 0001, 0100, and
0110, respectively.
58

Binary-Coded Decimal (BCD)


• Because most computers use bytes as the smallest unit of access, most values
are stored in 8 bits, not 4.
• That gives us two choices for storing 4-bit BCD digits:
 We can ignore the cost of extra bits and pad the high-order nibbles (half-byte)
with zeros, forcing each decimal digit to be replaced by 8 bits.
• Using this approach, padding with zeros, 146 would be stored as:
00000001 00000100 00000110
• Clearly, this approach is quite wasteful.
 The second approach, called packed BCD, stores two digits per byte.
• Packed decimal format allows numbers to be signed, but instead of putting the
sign at the beginning, the sign is stored at the end.
• The standard values for this “sign digit” are 1100 for +, 1101 for –, and 1111 to
indicate that the value is unsigned.
• Using packed decimal format, +146 would be stored as 00010100 01101100.
59

Binary-Coded Decimal (BCD)


• Another variation of BCD is zoned decimal format.
• Zoned decimal representation stores a decimal digit in the low-order nibble of
each byte, which is exactly the same as unpacked decimal format.
• However, instead of padding the high-order nibbles with zeros, a specific
pattern is used.
• There are two choices for the high-order nibble, called the numeric zone:
 EBCDIC (Extended Binary Coded Decimal Interchange Code) zoned decimal
format requires the zone to be all ones (hexadecimal F).
 ASCII zoned decimal format requires the zone to be 0011 (hexadecimal 3).
• Both formats allow for signed numbers (using the sign digits) and typically
expect the sign to be located in the high-order nibble of the least significant
byte.
• For example, +146 in EBCDIC zoned decimal format is 11110001 11110100
11000110 (note that the high-order nibble of the last byte is the sign).
• In ASCII zoned decimal format, +146 is 00110001 00110100 11000110.
60

Binary-Coded Decimal (BCD)


• Example: Represent –1265 using packed BCD and EBCDIC zoned decimal.
• The 4-bit BCD representation for 1265 is: 0001 0010 0110 0101
• Adding the sign after the low-order digit and padding the high-order bit with
0000, we have:

• The EBCDIC zoned-decimal representation requires 4 bytes:


61

ASCII
• Many applications of digital computers require the handling not only of
numbers but also of other characters or symbols, such as the letters of the
alphabet.
• For instance, consider a company with thousands of employees. To represent
the names and other pertinent information, it is necessary to formulate a
binary code for the letters of the alphabet.
• In addition, the same binary code must represent numerals and special
characters (such as $).
• The standard binary code for the alphanumeric characters is the American
Standard Code for Information Interchange (ASCII), which uses seven bits to
code 128 characters.
• The letter A, for example, is represented in ASCII as 1000001 = 65.
62

Unicode
• Both EBCDIC and ASCII were built around the Latin alphabet.
• As such, they are restricted in their abilities to provide data representation for
the non-Latin alphabets used by the majority of the world’s population.
• As all countries began using computers, each was devising codes that would
most effectively represent their native languages.
• None of these was necessarily compatible with any others, placing yet another
barrier in the way of the emerging global economy.
• In 1991, before things got too far out of hand, a consortium of industry and
public leaders was formed to establish a new international information
exchange code called Unicode.
• This group is appropriately called the Unicode Consortium.
• Unicode is a 16-bit alphabet.
• Because the base coding of Unicode is 16 bits, it has the capacity to encode the
majority of characters used in every language of the world.
63

Bibliography

 Andrew S. Tanenbaum, Todd Austin. Structured computer organization.


Pearson. 2013.
 David A. Patterson, John L. Hennessy. Computer Organization and Design.
Elsevier. 2021.
 Linda Null. Essentials of Computer Organization and Architecture. Jones &
Bartlett Learning. 2023.
 William Stallings. Computer Organization and Architecture. Pearson. 2021.
 M. Morris Mano, Michael D. Ciletti. Digital Design. Pearson. 2019.
 ….
64

Thank you for your attention

You might also like