Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 66

Chapter 2

Data Representation in
Computer Systems

Prepared by Dr. Ahmad Mikati


Lecture Overview
Introduction to this Lecture's activities
In this lecture, you will learn the essentials of numbering systems, and converting
between bases. The content provides thorough coverage of the various means
computers use to represent both numerical and character information. You will
also learn three methods for representing signed numbers: signed magnitude,
one’s complement, and two’s complement. In addition, you will learn how to
represent numbers using Floating-Point Representation.
After completing the lecture, you will be able to:

1. Describe the fundamentals of numerical data representation and manipulation


in digital computers.

2. Master the skills of converting between various bases.

3. Recognize the three ways in which signed binary integers may be expressed.

4. Describe the fundamental concepts of floating-point representation.


November 27, 2023 TM103- Arab Open University 2
Lecture Overview

 Positional Numbering System


 Conversions
 Signed integer representation
 Floating-point representation

November 27, 2023 TM103- Arab Open University 3


Positional Numbering System

The general idea behind positional numbering system is that a


numeric value is represented through increasing powers of a base.
This is often referred to as a weighted numbering system because
each position is weighted by a power of the base.

Numbering systems and their properties:


 Any numeric value is represented through increasing powers of a base.
 The set of valid numerals (digits) is equal in size to the base of that system.
 The least numeral is 0 and the highest one is 1 smaller than the base.
 Adding 1 to the highest numeral gives you 10.

November 27, 2023 TM103- Arab Open University 4


Positional Numbering System
 The most important bases in computer science are:
• Decimal
- The base is 10
- The number of valid numerals is 10 (equal to the base)
- The set of valid numerals is: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
- Adding 1 to the highest numeral gives you 10 : 9+1=10
• Binary
- The base is 2
- The number of valid numerals is 2 (equal to the base)
- The set of valid numerals is: {0 , 1}
- Adding 1 to the highest numeral gives you 10 : 1+1=10
• Octal
- The Base is 8
- The number of valid numerals is 8 (equal to the base)
- The set of valid numerals is: {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7}
- Adding 1 to the highest numeral gives you 10 : 7+1=10
• Hexadecimal
- The base is 16
- The number of valid numerals is 16 (equal to the base)
- The set of valid numerals is: {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , A , B , C , D , E , F}
November 27, 2023
- Adding 1 to the highest numeral
TM103-gives
Arabyou
Open
10University
: F+1=10 5
Positional Numbering System
 To distinguish among numbers in different bases, we use the base as a
subscript, such as 2310.
 Numbers written without a subscript should be assumed to be
decimal.
 Any decimal integer can be expressed exactly in any other integral
base system, and vice versa.

Example:
• 243.5110 = 2x102 + 4x101 + 3x100 + 5x10-1 + 1x10-2
• 10110.012 = 1x24 + 0x23 + 1x22 + 1x21 + 0x20 + 0x2-1 + 1x2-2= 22.2510

 Pay attention to the fact that the first position (right-hand side) of the integer
part, will be multiplied by the base raised to power (0), and the first position
(left-hand side) of the fractional part will be multiplied by the base raised to
power (-1).
• You can notice that in the above example, where 243.5110, 3 was multiplied by 100,
November 27, 2023 TM103- Arab Open University 6
and 5 was multiplied by 10 .
-1
Lecture Overview

 Introduction
 Positional Numbering System
 Converting from Decimal to any Base
 Converting from any Base to Decimal
 Converting between Bases
 Converting Between Power-of-Two Bases
 Signed integer representation
 Floating-point representation
November 27, 2023 TM103- Arab Open University 7
Converting from Decimal to any Base
 When dealing with numbers, you might face ones that contain
fractions. A number, hence may include an integer part and a
fraction part separated by a base point.

 Base points separate the integer part of a number from its fractional
part. The “Base point” is called a “decimal point” in a decimal
system, a “binary point” in a binary system, and so on.

We will split our discussion about converting a number into two phases:

• Phase one that deals with the integer part.

• Phase two that deals with the fraction part.

November 27, 2023 TM103- Arab Open University 8


Converting from Decimal to any Base
Converting the integer part
Given the integer part of a decimal number, you can find the
equivalent value in any base, n, as follows:
1. Divide the number by n.
2. You will get Quotient and Remainder. The remainder will
always be less than the base n. Keep this remainder aside.
3. Use the quotient to repeat the above steps, until you get a
quotient equal to 0.
4. Now, group the remainders in order, such that the first
remainder will be the least significant bit, and the last
one will be the most significant bit.
Note that the highest-order bit is the leftmost bit, and it is called the most significant bit
(MSB).
On the other hand, the lowest-order bit is the rightmost bit, and it is called the least
significant bit (LSB).
November 27, 2023 TM103- Arab Open University 9
Converting from Decimal to any Base
Example: Convert 11310 to binary
Q R
2 |113 56 1 LSB
2 |56 28 0
14 0
2 |28
7 0 11310 = 11100012
2 |14 3 1
2 |7 1 1
2 |3 0 1 MSB
2 |1
0 A binary number with N bits can represent 2 unsigned integers from 0 to 2 -1.
Important note: N N

November 27, 2023 TM103- Arab Open University 10


Converting from Decimal to any Base

 Keep in mind the following tables or how to obtain


them!

November 27, 2023 TM103- Arab Open University 11


Converting from Decimal to any Base
Converting the fraction part
 Fractions in a decimal system can be converted/approximated to
fractions in any other Base using negative powers of a base.
 Example of fractions (the integer part is italic and the fractional part is
bold)
• Base 10 : 2390167.1208
• Base 2 : 1011110.111011

 Because the remainder method works with positive powers of the base
for conversion of integers, it makes sense that we would use
multiplication to convert fractions, because they are expressed in
negative powers of the base.

 However, instead of looking for the remainder, as we did above, we use


only the integer part of theTM103-
November 27, 2023
product after
Arab Open multiplication by the base. 12
University
Converting from Decimal to any Base
Converting the fractional part
Given the fractional part of a decimal number, you can find the
equivalent value in any base, n, as follows:
1. We multiply the fraction by the base n.
2. We deduct the integer part from the product, and keep it aside.
3. We take the remaining fraction, and repeat the process with the
new value, until the fraction is zero or if we have enough digits
after the base point.
4. We group the deducted integers that have been put aside, from
top to bottom instead of bottom to top, and then we put them in
the fraction form.

The next examples illustrate the process.


November 27, 2023 TM103- Arab Open University 13
Converting from Decimal to any Base

 To convert fractions from decimal to any other base system we repeatedly


multiply by the destination base.
 Example: Convert 0.430410 to base 5.
0.4304
x 5
2.1520 The integer part is 2
0.1520
x 5
0.7600 The integer part is 0 0.430410 = 0.20345
x 5
3.8000 The integer part is 3
0.8000
x 5
4.0000 The integer part is 4,
the fractional part isTM103-
November 27, 2023
zero,Arab
we are done
Open University 14
Converting from Decimal to any Base
Converting the fractional part Example:
Convert 0.3437510 to binary with 4 bits to the right of the binary point.

0.34375
x2
0.68750 The integer part is 0
x2
1.37500 The integer part is 1
0.37500
x2
0.75000 The integer part is 0
x2
1.50000 The integer part is 1

This is our fourth bit.


0.3437510 = 0.01012
We will stop here.
November 27, 2023 TM103- Arab Open University 15
Lecture Overview

 Introduction
 Positional Numbering System
 Converting from Decimal to any Base
• Converting the integer part
• Converting the fraction part
 Converting from any Base to Decimal
 Converting between Bases
 Converting Between Power-of-Two Bases
 Signed integer representation
 Floating-point representation
November 27, 2023 TM103- Arab Open University 16
Converting from any Base to Decimal
Converting from any Base to Decimal
To convert from any base, say n, to decimal, all you need to do is
to multiply the digits, whether they were integers or fractions, by
the base n raised to the position of that digit.
Thus, given a number in base n, you can find the equivalent
value in decimal as follows:
1. Multiply each digit with the base n raised to the power of its
location.(Note that the LSB digit has a position of 0, and the digits after
the base point (fraction part) have negative powers starting from -1)
2. Add all the intermediate results to get the final equivalent
decimal value.

November 27, 2023 TM103- Arab Open University 17


Converting from any Base to Decimal
Example 1: Suppose that we want to convert the binary number 10.11
to its decimal equivalent:
(1 * 21) + (0*20) + (1*2-1) + (1*2-2) = 2+ 0+ 0.5+ 0.25 = 2.7510

Note: In the hexadecimal system, you might encounter a letter. In this


case, you should multiply the respective equivalent value in decimal
with n raised to the position.

Example 2: Suppose that we want to convert the Hexadecimal number


1A.5 to its decimal equivalent:

(1 * 161) + (A*160) + (5*16-1) = (1 * 161) + (10*160) + (5*16-1)

= 16 + 10+ 0.3125 =26.312510

November 27, 2023 TM103- Arab Open University 18


Lecture Overview

 Introduction
 Positional Numbering System
 Converting from Decimal to any Base
• Converting the integer part
• Converting the fraction part
 Converting from any Base to Decimal
 Converting between Bases
 Converting Between Power-of-Two Bases
 Signed integer representation
 Floating-point representation
November 27, 2023 TM103- Arab Open University 19
Converting Between Bases
Converting Between Bases
Although there are direct ways to convert any number in any
base to any other base, it is faster and more accurate to convert
to base 10 and then to the desired base. One exception to this
rule exists when you are working between bases that are
powers of two, as you will see later in this section.

In general, when you want to convert from Base x To Base y, you


can use Base 10 as an intermediate step of conversion.

Base x Decimal Base y

November 27, 2023 TM103- Arab Open University 20


Converting Between Bases
Example: Convert 31214 to base 3.
First, convert to decimal: Second, convert to base 3:
Q R
31214= 3* 43 + 1*42 + 2*41 + 1*40
217 / 3 = 72 1
72 / 3 = 24 0
= 3*64 + 1*16 + 2*4 + 1
24 / 3 = 8 0
= 21710 8/3 = 2 2
2/3 = 0 2

Then, 31214= 220013

November 27, 2023 TM103- Arab Open University 21


Converting Between Bases
The binary numbering system is the most important base system for
digital computers.

However, it is difficult to read long strings of binary numbers—and


even a modestly-sized decimal number becomes a very long binary
number.

For example: 110101000110112 = 1359510

For compactness and ease of reading, binary values are usually


expressed using the hexadecimal or octal numbering system.

Working between bases that are powers of two, is much easier than
other bases.

In the next section, you will learn in details how to convert among
these
November bases.
27, 2023 TM103- Arab Open University 22
Lecture Overview

 Introduction
 Positional Numbering System
 Converting from Decimal to any Base
• Converting the integer part
• Converting the fraction part
 Converting from any Base to Decimal
 Converting Between Power-of-Two Bases
 Signed integer representation
 Floating-point representation
November 27, 2023 TM103- Arab Open University 23
Converting Between Power-of-Two Bases
Converting Between Power-of-Two Bases
The most famous power-of-two bases are: binary (base 2), octal (base 23
- base 8) and hexadecimal (base 24 - base 16).

Each octal digit is equivalent to a group of 3 binary digits called octet.

Each hexadecimal digit is equivalent to a group of 4 binary digits called


hextet.

We convert from binary to octal and from binary to hexadecimal by


simply grouping bits

November 27, 2023 TM103- Arab Open University 24


Converting Between Power-of-Two Bases

Binary to Octal Conversion:

To convert from binary to octal, we do the following:


1. Make Groups of 3 bits (from right to left for the integer part, from
left to right for the fraction part)

2. Add zero(s) (on the left for the integer part, on the right for the
fraction part) to complete the last octet (if not complete)

3. Convert each octet to its corresponding octal digit

4. Concatenate ( join together) the digits. (Do not add them!)

November 27, 2023 TM103- Arab Open University 25


Converting Between Power-of-Two Bases
Example: Suppose that we want to convert the Binary
number 101100100111012 to octal:
1. Make Groups of 3 bits (from right to left): 10 110 010 011
101

2. Add zero(s) on the left to complete the last octet: 010 110 010 011
101

3. Convert each octet to its corresponding octal digit

010 110 010 011 101

2 6 2 3 5

4. Concatenate: 101100100111012 = 262358

November 27, 2023 TM103- Arab Open University 26


Converting Between Power-of-Two Bases

Binary to Hexadecimal Conversion:


To convert from binary to hexadecimal, we do the
following:
1. Make Groups of 4 bits (from right to left for the integer part, from left
to right for the fraction part)

2. Add zero(s) (on the left for the integer part, on the right for the
fraction part) to complete the last hextet (if not complete)

3. Convert each hextet to its corresponding Hexadecimal digit.

4. Concatenate (Do not add!) the digits.

November 27, 2023 TM103- Arab Open University 27


Converting Between Power-of-Two Bases
Example: Convert 101100100111012 to
hexadecimal.
1. Make Groups of 4 bits (from right to left): 10 1100
1001 1101

2. Add zero(s) on the left to complete the last hextet: 0010 1100
1001 1101

3. Convert each hextet to its corresponding hexadecimal digit

0010 1100 1001 1101 (Reminder : 1101 is 1* 23 + 1*22 + 0*21 +


1*20= D)

2 C 9 D

4. Concatenate: 101100100111012 = 2C9D16


November 27, 2023 TM103- Arab Open University 28
Converting Between Power-of-Two Bases
Note: To convert from Hex to Octal, or from Octal to Hex, you
can simply use the Binary as an intermediate step of
conversion.

Octal Binary Hex

Hex Binary Octal

Example: Convert the Hex number 351B to Octal.

First, you need to convert from Hex to Binary.

Binary values are derived from Hex by representing each Hex digit by a group of
four binary bits.

Next, you have to convert from binary to Octal:


November 27, 2023 TM103- Arab Open University 29
3
Lecture Overview

 Introduction
 Positional Numbering System
 Converting from Decimal to any Base
• Converting the integer part
• Converting the fraction part
 Converting from any Base to Decimal
 Converting between Bases
 Converting Between Power-of-Two Bases
 Signed integer representation
 Floating-point representation
November 27, 2023 TM103- Arab Open University 30
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).

Signed binary integers may be expressed in three ways:


1. Signed magnitude
2. One’s complement
3. Two’s complement
Reminder: Binary addition is as easy as it gets. You need to know only four rules:
0+0= 0 0+1= 1
1+0= 1 1 + 1 = 10

November 27, 2023 TM103- Arab Open University 31


Signed integer representation
Signed Magnitude Representation
Signed magnitude is the most intuitive method for
representing the unsigned numbers.
The MSB (Most Significant Bit) of a binary number is kept as
the “sign” of the number
MSB = 1: negative number
MSB = 0: positive number
The remaining bits represent the magnitude (or absolute
value) of the numeric value.

November 27, 2023 TM103- Arab Open University 32


Signed integer representation
Example: In an 8-bit word signed magnitude system give the decimal
representation of the following numbers: 00000001, 10000001
Answer:
•00000001:
-The MSB is 0: The number is positive
-The remaining 7 bits are: 00000012 = 110
-The decimal number is +1
•10000001:
-The MSB is 1: The number is negative
-The remaining 7 bits are: 00000012 = 110
-The decimal number is -1
In an N bit word signed magnitude system
 1 bit is used for the sign of the number (MSB).
 N-1 bits are used for the magnitude of the number.
 The largest integer is 2N-1- 1
 The smallest integer is -(2N-1- 1)
November 27, 2023 TM103- Arab Open University 33
Signed integer representation
Adding numbers in Signed Magnitude:
When adding two numbers using signed magnitude, we add all digits
excluding the sign bits. If we have a carry out 1 from the seventh bits
addition, then this 1 will be discarded.
Moreover, you might counter two types of additions. The first type is
adding operands having the same sign, and the second type is adding
operands having different signs.
1- Adding operands that have the same sign:
The steps that you have to follow are the following:
a. Carry out the addition.
b. If while adding the seventh bits to the left, there is a carry 0, we can
be sure that the addition is correct, and the result is correct.
c. If while adding the seventh bits to the left, there is a carry 1, we say
that we have an overflow condition and the carry is discarded,
resulting in an incorrect sum.
November 27, 2023 TM103- Arab Open University 34
Signed integer representation
Adding numbers in Signed Magnitude:
When adding two numbers using signed magnitude, we add all digits excluding the sign
bits. If we have a carry out 1 from the seventh bits addition, then this 1 will be discarded.
1- Adding operands that have the same sign:
The steps that you have to follow are the following:
a. Carry out the addition.
b. If while adding the seventh bits to the left, there is a carry 0, we can be sure that the addition is
correct, and the result is correct.
c. If while adding the seventh bits to the left, there is a carry 1, we say that we have an overflow
condition and the carry is discarded, resulting in an incorrect sum.

Example 1: Add 010011112 to 001000112 using signed-magnitude arithmetic.


Sign 1 1 1 1 ⇐ carries
0 1001111 (79)
0 + 0100011 (35)
_________________________

0 1110010 (114)

We find 010011112 + 001000112 = 011100102 in signed-magnitude representation. (no overflow)


November 27, 2023 TM103- Arab Open University 35
Signed integer representation

Example 2: Add 010000012 to 011000012 using signed-magnitude arithmetic.

1 (discarded) 1 ⇐ carries
0 1000001 (65)
0 +1100001 ( 97)
______________
0 0100010 (34) which is erroneous!

• The addition overflows


• The last carry is discarded
• The result is incorrect

November 27, 2023 TM103- Arab Open University 36


Signed integer representation
2-Adding operands that have different signs
The steps that you have to follow are the following:
a. Determine which operand has the larger magnitude.
b. The magnitude of the result must be obtained by subtracting (not adding)
the operand with smaller magnitude from the operand with the lager one.
c. The sign of the result is the same as the sign of the operand with the larger
magnitude.

Example: Add 110011112 (-79) to 011000112 (99) using signed-magnitude arithmetic.

0112 ⇐ borrows
0 1100011 (99)
1 - 1001111 (-79)
_____________
0 0010100 (20)

We find 011000112 + 110011112= 000101002 in signed-magnitude representation.

November 27, 2023 TM103- Arab Open University 37


Signed integer representation
Summary:

 Signed magnitude representation is easy for people to


understand, but it requires complicated computer hardware.
 Another disadvantage of signed magnitude is that it allows
two different representations for zero: positive zero and
negative zero ( 00000000 & 10000000).
 For these reasons (among others), computers systems
employ complement systems for numeric value
representation.

November 27, 2023 TM103- Arab Open University 38


Signed integer representation
Complement system
The Complement system is used to represent/convert negative numbers
only. Hence, positive numbers stay as is, without any change.
For a positive number, the complement systems will have the same positive
representation as that of the signed magnitude representation.

When using complement system, the subtraction is converted to addition,


which means that you do not have a subtraction operation when using
one’s or two’s complement.

Advantages of the complement system


 Simplify computer arithmetic
 No need to process sign bits separately
 The sign of a number is easily checked by looking at its high-order bit (MSB).

November 27, 2023 TM103- Arab Open University 39


Signed integer representation
One’s complement (C1)
A positive number in one’s complement (C1), is directly converted to its
binary representation. The result of this positive number is the same as that
of the signed magnitude representation.

To convert a negative number to its one’s complement (C1), this number is


subtracted from all ones, or you can simply complement each digit, such
that the 1s become 0s and vice versa.
Example 1:
The one’s complement of 0101 is 1111 - 0101 = 1010 C1
Or, you can simply complement it:
01012 positive number
1010 negative number, in C1
Example 2: Express 2310 and -910 in 8-bit binary one’s complement form.
Answer:
2310 = + (000101112) = 00010111C1
-910 = - (000010012) = 11110110C1
November 27, 2023 TM103- Arab Open University 40
Signed integer representation
Reading the value of a C1 number:
In order to find an equivalent decimal value of a C1 number, you have
to:
Check the MSB:
1. If it is 0, then you can directly convert the binary to decimal.
2. If it is 1, then :
a. Complement the digits.
b. Convert the binary number to decimal.
c. Include the negative sign.
Example: What is the decimal equivalent of the C1 number 11110110 ?

Answer: Here, you can notice that the MSB is 1. Then, you have to complement all
the bits of the C1 number first, and then find the equivalent value in decimal.
Finally, remember to add the negative sign.
11110110C1
Complement: 000010012
Convert :9
Include (-) : -9
November 27, 2023 TM103- Arab Open University 41
Signed integer representation
Adding numbers in C1:
In one’s complement, the subtraction is converted into addition.
For example: 2310 – 910 = 2310 + (-910).

In C1, we add all digits including the sign bits. If we have a carry out 1 from the
eighth bits addition, then this 1 will be added to the sum.
Example 1: Add 2310 to -910 using 8-bit binary one’s complement arithmetic .
In a previous example, we have calculated the C1 values of 23 and -9.

Now, we will add both:

Reminder: In C1, the last carry is added to the result.


November 27, 2023 TM103- Arab Open University 42
Signed integer representation
Example 2: Using one’s complement binary arithmetic, find the sum of 48
and – 19.
We note that 19 in binary is 00010011.
Therefore, -19 in one’s complement is:11101100

Summary:
Although the “end carry around” adds some complexity, one’s complement is
simpler to implement than signed magnitude.
Nevertheless, it still has the disadvantage of having two different representations
for zero: positive zero and negative zero (00000000 & 11111111).
Two’s complement solves this problem.
November 27, 2023 TM103- Arab Open University 43
Signed integer representation
Two’s Complement Representation
In One’s complement, we still have two representations for zero: 00000000
and 11111111. Computer engineers long ago stopped using one’s
complement.
A more efficient representation for binary numbers is: two’s complement.

C2 is nothing more than C1 incremented by 1!


Example: Express 2310, -2310, and -910 in 8-bit binary two’s complement form.

2310 = + (000101112) = 00010111c2 (no need to complement, as it is a positive number)

-2310 = -(000101112) = 11101000c1 + 1 = 11101001c2

-910 = -(000010012) = 11110110c1 + 1 = 11110111c2

November 27, 2023 TM103- Arab Open University 44


Signed integer representation
Reading the value of a C2 number:
In order to find the equivalent decimal of a C2, you have to:
Check the MSB:
a. If it is 0, then you can directly convert the binary to decimal.
b. If it is 1, then :
1. Complement the digits.
2. Add 1 .
3. Convert the binary number to decimal.
4. Include the negative sign.

Example: What is the decimal equivalent of the C2 number 11110110?


Here, you can notice that the MSB is 1. Then, you have to complement all the bits of the C2
number first, add one, and then find the equivalent value in decimal. Finally, remember to add
the negative sign.
11110110C2
Complement: 00001001
Add 1 : 00001010
Convert : 10
Include (-) : -10
November 27, 2023 TM103- Arab Open University
45
Signed integer representation
Adding numbers in C2:
In two’s complement, the subtraction is also converted into addition.

Unlike C1 arithmetic, in C2 the last carry is discarded.

Example 1: Add 910 to -2310 using two’s complement arithmetic.

11110010 -(00001101 + 1 )= -14

The result is 11110010C2 = -(000011102) = -1410

November 27, 2023 TM103- Arab Open University 46


Signed integer representation
Example 2: Find the sum of 2310 and -910 in binary using
two’s complement arithmetic.
2310 = +(00010111)2 = 00010111C2
-910 = -(00001001)2 = 11110111C2
2310 + (-910) = 00010111C2 + 11110111C2

Carries: 1 1 1 1 0 1 1 1
0 0 0 1 0 1 1 1 2310
+ 1 1 1 1 0 1 1 1 + (-910)
0 0 0 0 1 1 1 0 +1410

Result: 00001110C2 = +(000011102) = 1410


November 27, 2023 TM103- Arab Open University 47
Signed integer representation
Overflow in complement systems (C1 and C2)
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 if a positive and a
negative number are being added together.
To Detect Overflow:
Check the “carry-in” and the “carry-out” of the sign bit:
 If these are different: there is an overflow
 If these are equal: there is no overflow

November 27, 2023 TM103- Arab Open University 48


Signed integer representation

Example: Add 10610 to 4610 using two’s complement arithmetic.

As you can see, the carry-in is 1, while the carry-out is 0. Since the two
carries are different, we have an overflow and an erroneous result
(- 106, where the result should be 152)

November 27, 2023 TM103- Arab Open University 49


Signed integer representation

Advantages of two’s complement


• It is the most popular choice for representing signed
numbers
• The algorithm for adding and subtracting is quite easy
• It has the best representation for 0 (all 0 bits)
• It is self-inverting
• It is easily extended to larger numbers of bits.

November 27, 2023 TM103- Arab Open University 50


Lecture Overview

 Introduction
 Positional Numbering System
 Converting from Decimal to any Base
 Converting from any Base to Decimal
 Converting between Bases
 Converting Between Power-of-Two Bases
 Signed integer representation
 Floating-point representation

November 27, 2023 TM103- Arab Open University 51


Floating-point representation
A Simple Floating-Point Representation Model
The signed magnitude, one’s complement, and two’s complement
representation that we have just presented deal with signed integer values
only.

Without modification, these formats are not useful in scientific or business


applications that deal with real number values.

Floating-point representation solves this problem.


Floating-point numbers allow an arbitrary number of decimal places to the
right of the decimal point.

Floating-point numbers allow an arbitrary number of decimal places


to the right of the decimal point. For example: 0.5  0.25 = 0.125

They are often expressed in scientific notation.


 For example: 0.125 = 1.25  10-1
November 27, 2023 TM103- Arab Open University 52
Floating-point representation
Computers use a form of scientific notation for floating-point representation.
Numbers written in scientific notation have three components:

In digital computers, floating-point numbers consist of three parts:


• A sign bit
• An exponent part: representing the exponent on a power of 2,
• A fractional part called a significand: which is a fancy word for a mantissa.

November 27, 2023 TM103- Arab Open University 53


Floating-point representation
We introduce a hypothetical “Simple Model” to explain the concepts
In this model:
- A floating-point number is 14 bits in length
- The sign bit field is 1 bit
- The exponent field is 5 bits
- The significand field is 8 bits

The significand is always preceded by an implied binary point.


Thus, the significand always contains a fractional binary value.
The exponent indicates the power of 2 by which the significand is multiplied.

November 27, 2023 TM103- Arab Open University 54


Floating-point representation
Example: Express 3210 in the simplified 14-bit floating-point model.

We know that 32 is 25. The scientific notation 32 = 1.0 x 2 5 = 0.1 x 26. (In a moment, we will
explain why we prefer the second notation versus the first.)

- Since we have a positive number, then the bit sign is 0.


- Since we have five bits in the exponent field, 6 will be represented as 00110.
- Since we have eight bits in the significand field, the value will be 10000000.

Using this information, we put 0 in the sign field, 00110 (= 610) in the exponent field
and 10000000 in the significand as shown.
3210 will be:

and -3210 will be:


So, why did we choose in the above example to represent 32 by the
second notation (0.1 x 26)?
November 27, 2023 TM103- Arab Open University 55
Floating-point representation
To resolve the problem of synonymous forms, we establish a
rule that the first digit of the significand must be 1, with no ones
to the left of the base point.

This process, called normalization, results in a unique pattern


for each floating-point number.

In our simple model, all significands must have the form


0.1xxxxxxxx
For example, 4.5 = 100.1 x 20 = 1.001 x 22 = 0.1001000 x 23. The
last expression is correctly normalized.

November 27, 2023 TM103- Arab Open University 56


Floating-point representation
Exercise: Represent the number 19 in a 14 bits floating-point representation

1910 = 100112 x 20 = 1001.12 x 21= 100.112 x 22


= 10.0112 x 23 = 1.00112x 24 = 0.100112 x 25

As a convention, we stop when the MSB of the significand is “1”: 0.100112 x


25

 The sign bit is 0, since the number is positive.


 The exponent is 510 = 001012
 The significand is: 100112 → 100110002 (since we need 8 bits representation)
Therefore, the representation will be:

0 00101 10011000

November 27, 2023 TM103- Arab Open University 57


Floating-point representation
Excess-16 bias Floating-Point Representation Model
One obvious problem with the simple model is that we have not
provided a room for the negative exponents.

As you already know from previous lectures, fractions are


represented using negative powers.

If we wanted to store 0.25, we would have no way of doing so,


because 0.25 is 2-2 and the exponent -2 cannot be represented.

We could fix the problem by adding a sign bit to the exponent, but
it turns out that it is more efficient to use a biased exponent,
because we can use simpler circuits designed specifically for
unsigned numbers when comparing the values of two floating-
point
Novembernumbers.
27, 2023 TM103- Arab Open University 58
Floating-point representation
To solve such problems we use an excess-16 bias:
 All negative and positive exponents are added by 16
 We say that the real exponent is replaced by a biased
exponent
 All exponents are converted to positive biased exponents

With an excess-16 bias:


 Exponent values less than 16 will indicate negative exponent
values
 Exponent values more than 16 will indicate positive exponent
values
 Exponents of all zeros or all ones are typically reserved for
special numbers.
November 27, 2023 TM103- Arab Open University 59
Floating-point representation

Example 1: Represent the number 19 in a 14 bits


floating point form with excess-16 bias
• The number is positive: sign bit is “0”
• 1910= 0.100112 x 25
• The exponent is 510 → (5+16)10 = 2110 = 101012
• The significand is: 100112 → 100110002
• So 19 in floating point form with excess-16 bias is:

November 27, 2023 TM103- Arab Open University 60


Floating-point representation

Example 2: Represent the number -0.2510 in a 14 bits


floating point form with excess-16 bias.

• The number is negative: sign bit is “1”


• 0.25 = 0.012 x 20 = 0.12 x 2-1
• The exponent is -110  (-1+16)10 = 1510 = 011112
• The significand is 1  10000000
• So, -0.25 in floating point form with excess-16 bias is:

November 27, 2023 TM103- Arab Open University 61


Floating-point representation

Example 3: Express -0.0312510 in normalized floating-


point form with excess-16 bias.

• The number is negative: sign bit is “1”


• 0.0312510 = 0.000012 = 0.00001x20 = 0.1x2-4
• The exponent is -410 → (-4+16)10 = 1210 = 011002
• The significant is 1 → 10000000
• So -0.03125 in floating point form with excess-16 bias is:

1 0 1 1 0 0 1 0 0 0 0 0 0 0

November 27, 2023 TM103- Arab Open University 62


Floating-point representation

Floating-point Arithmetic
To add/subtract two numbers in floating point form, both numbers should
have the same exponent.
If exponents are different, you should change one of the numbers so that
both of them are expressed in the same power of the base. Then, you add
the binary numbers, and represent the result in a normalized floating-point
form.
Example: Add the following binary numbers as represented in a normalized
14-bit format with an excess-16 bias.

Looking at the exponents fields, you can notice that they are different:
The first representation has an exponent value 1810 → 210 (you deduct the 16 that is already
added, as you are working with excess-16 bias)
The second representation has an exponent value 1610 → 010 (you also deduct the 16)
November 27, 2023 TM103- Arab Open University 63
Floating-point representation
Let us explain the representation of each number.
The first number is 0.11001000x22 (recall that the fraction is derived from the
significand field)

The second number is 0.10011010x20

Now, change one of the numbers so that both of them will have the same exponent.
We will change the first number, so that its exponent will be 0 instead of 2:

0.11001000x22 = 11.001000x20 ( you simply shift the binary point two places to the
left)

Now, the numbers are ready to be added: 11.001000 2 + 0.100110102


0.1 0 0 1 1 0 1 0
+ 1 1.0 0 1 0 0 0 0 0
1 1.1 0 1 1 1 0 1 0

The result is 11.10111010 x 20

November 27, 2023 TM103- Arab Open University 64


Floating-point representation

Following the agreed-upon procedure, we will normalize the result:


11.10111010 x 20 = 0.1110111010 x 22 (We truncate the fractional number in
order to get an 8-bit significand)
= 0.11101110 x 22

In floating-point form with excess-16, the representation will be:

November 27, 2023 TM103- Arab Open University 65


End of Chapter 2

Try to solve all exercises related to chapter 2

You might also like