0% found this document useful (0 votes)
119 views66 pages

CSI104 Slot05

The document discusses how different types of data are stored in computers, including numbers, text, audio, images, and video. It describes how integers and real numbers are stored using fixed-point and floating-point representations. It also explains how text, audio, images, and video are converted to binary formats and stored in computer memory.

Uploaded by

Người Lạ
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)
119 views66 pages

CSI104 Slot05

The document discusses how different types of data are stored in computers, including numbers, text, audio, images, and video. It describes how integers and real numbers are stored using fixed-point and floating-point representations. It also explains how text, audio, images, and video are converted to binary formats and stored in computer memory.

Uploaded by

Người Lạ
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/ 66

Week Slot Content Assessment Chapters

01 1+2 Computer Organisation Lab 1 (p1) Chapter 1, 5


3 Computer Organisation (cont.) Chapter 1, 5
02
4 Numbering Systems Lab 1 (p2) Chapter 2
5 Data Storage & Operations on Data Lab 1 (p3) Chapter 3, 4
03
6 Computer Networks & Internet Progress Test 01 Chapter 6
04 7+8 Operating Systems Lab 2 (p1) Chapter 7
05 9 + 10 Algorithms Presentation 01 Chapter 8
06 11 + 12 Programming Lab 2 (p2) – short preso Chapter 9
13 Software Engineering Chapter 10
07
14 Data Structures Lab 2 (p3) – short preso Chapter 11, 12
Presentation 02
08 15 + 16 Data Structures (cont.) Chapter 11, 12
Progress test 02
17 File Structure Chapter 13
09
18 Database Lab 2 (p4) Chapter 15
19 Database (cont.) Chapter 15
10
20 Security & Ethical issues Progress test 03 Chapter 20
1
CSI104 Week 03

DATA STORAGE

Tam Nguyen (FU HL- SE)


Jan 2023
CONTENT

1. Data types

2. Storing Numbers

3. Storing Text, Audio, Image, Video

3
Objectives

After studying this chapter, the student should be able to:


• List five different data types used in a computer.
• Describe how integers are stored in a computer.
• Describe how reals are stored in a computer.
• Describe how text is stored in a computer using one of the various encoding systems.
• Describe how audio is stored in a computer using sampling, quantization and encoding.
• Describe how images are stored in a computer using raster and vector graphics schemes.
• Describe how video is stored in a computer as a representation of images changing in time.

4
CONTENT

1. Data types

2. Storing Numbers

3. Storing Text, Audio, Image, Video

5
INTRODUCTION

Data today comes in different forms including numbers, text, audio, image,
and video.

Data

Numbers Text Audio Images Video

The computer industry uses the term multimedia to define information


that contains numbers, text, audio, images, and video.

Figure 3.1. Different types of data


6
DATA INSIDE A COMPUTER

• All data types are transformed into a uniform representation when stored in a
computer and transformed back to their original form when retrieved.
• This universal representation is called a bit pattern or a sequence of 0s and 1s.

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

Figure 3.2. A bit pattern

• Bits: The symbol 0 or 1 is called a bit (binary digit), the smallest unit of data that can
be stored in a computer.

• Bits patterns: a sequence, or a string of bits. A bit patterns with 8 bits is called a byte.
7
STORAGE OF DIFFERENT DATA TYPES

Figure 3.3. Storage of different data types 8


CONTENT

1. Data types 2.1. Storing Integers


• Unsigned Integers
2. Storing Numbers • Sign-and-magnitude representation
• Two’s complement representation
3. Storing Text, Audio, Image, Video 2.2. Storing Reals
• Floating-point representation
• Normalisation
• IEEE – Sign, exponent, and mantissa

9
INTRODUCTION

• A number is changed to the binary system before being stored in the computer
memory. Two issues exist:
1. How to store the sign of the number
2. How to show the decimal point
• There are several ways to handle the sign issue (discussed later).
• For the decimal point, computers use two different representations: fixed-point
and floating point.

To store
To store an integer
a real
10
2.1. STORING INTEGERS

• Integers are whole numbers (numbers without a fractional part).


o E.g., 134 and −125 are integers; 134.23 and −0.235 are not.

• An integer can be thought of as a number in which the position of the


decimal point is fixed: the decimal point is to the right of the least significant
(rightmost) bit.
à Fixed-point representation is used to store an integer

0 1 1 0 1 1 1 0 0 0 1 0 0 1 1 0 ●

Memory location
Decimal point
(assumed position)
Figure 3.4. Fixed-point representation of integers 11
UNSIGNED Representation

An unsigned integer has the range [0 . . . +∞].


An input device stores an unsigned integer using the following steps:
1. The integer is changed to binary.
2. If the number of bits is less than 𝑛, 0𝑠 are added to the left. Otherwise, overflow occurs.

Example: Store 7 in an 8-bit memory location using unsigned representation.


Solution:
• First change the integer to binary, (111)! .
• Add five 0𝑠 to make a total of eight bits, (00000111)! . The integer is stored in the memory location.

Change 7 to binary à 1 1 1

Add five bits at the left à 0 0 0 0 0 1 1 1


12
Overflow in UNSIGNED integers

What happens if we try to store an integer that is larger than 2! − 1 = 15 in


a memory location that can only hold 4 bits?

Figure 3.5. Overflow in unsigned integers 13


UNSIGNED Representation: Application

Unsigned integer representation can be used whenever we do not need negative


integers.
• Counting – We start counting from 1 (sometimes 0) & go up.
• Addressing – Addresses are positive integers starting from 0 (the 1st memory location) &
go up to an integer representing the total memory capacity. Here, negative integers are
unwanted.
• Storing other data types – Other data types (text, images, audio, and video) are stored
as bit patterns, which can be interpreted as unsigned integers.

14
SIGN-AND-MAGNITUDE Representation

• The available range for unsigned integers [0 . . 2! − 1] is divided into two equal sub-
ranges. The 1st half: positive integers; the 2nd half: negative integers.
• The range of numbers that can be stored in an n-bit location is
− 2!"# − 1 to + 2!"# − 1
• Note: there are two different representations for zero.

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

In sign-and-magnitude representation, the leftmost bit defines the sign of the integer.
If it is 0, the integer is positive. If it is 1, the integer is negative.

15
Overflow in SIGN-AND-MAGNITUDE representation

We may have both positive and negative overflow with signed integers.

Figure 3.6. Overflow in sign-and-magnitude representation using a 4-bit memory location 16


SIGN-AND-MAGNITUDE Representation: Application

Sign-and-magnitude representation is not used to store integers.


• Is used to store part of real numbers.
• Is used when we quantize an analog signal.

17
TWO’S COMPLEMENT Representation

Almost all computers use two’s complement representation to store a signed integer
in an 𝑛-bit memory location.
• For example, if 𝑛 = 4, the range is 0000 to 1111. This range is divided into two halves:
0000 to 0111 and 1000 to 1111.

Although the sign of the integer affects every bit in the binary integer stored, the first
(leftmost) bit determines the sign.

18
TWO’S COMPLEMENT Representation

Two’s complementing: taking the two’s complement of an integer in binary.


Two steps:
1. Copy bits from the right until a 1 is copied
2. Flip the rest of the bits

Example: Take the two’s complement of the integer 00110100.

Original integer 0 0 1 1 0 1 0 0
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
Two’s complementing once 1 1 0 0 1 1 0 0

19
TWO’S COMPLEMENTING (cont.)

Storing an integer in two’s complement format:


1. The absolute value of the integer is changed to an 𝑛-bit binary.
2. If the integer is positive or zero, it is stored as it is. If it is negative, the computer takes the
two’s complement of the integer and then stores it.

Example: Store 34 and −34 in 8-bit memory locations using 2’s complement representation

1. Covert to binary: (34)!" = (00100010)# 1. Covert to binary: (34)!" = (00100010)#


2. Since +34 is positive 2. Since −34 is negative
à Store +34 as 00100010 à 2’s complement:
11011110
à Store −34 as 11011110

20
TWO’S COMPLEMENTING (cont.)

Retrieving an integer in two’s complement format:


1. If the leftmost bit is 1, the computer applies the two’s complement operation to the
integer. If the leftmost bit is 0, no operation is applied.
2. The computer changes the integer to decimal.

Example: Retrieve the integer that is stored as 10001101 in memory in two’s complement format
1. Since the left most bit is 1, 2’s complement operation is applied
1 0 0 0 1 1 0 1
à 0 1 1 1 0 0 1 1
2. Change to decimal: (01110101)! = (117)"#
3. Sign is added: −117

21
Overflow in two’s complement representation

Figure 3.7. Overflow in two’s complement representation using a 4-bit memory location 22
2.2. Storing Reals

• A real is a number with an integral part and a fractional part.


o E.g., 23.7 is a real number — the integral part is 27 and the fractional part is 7/10.

• Although a fixed-point representation can be used to represent a real number, the


result may not be accurate, or it may not have the required precision.

Example:
In the decimal system, assume that we use a fixed-point representation with two digits at the
right of the decimal point and fourteen digits at the left of the decimal point, for a total of
sixteen digits. The precision of a real number in this system is lost if we try to represent a
decimal number such as 1.00234. The system stores the number as 1.00.

Real numbers with very large integral parts or very small fractional parts should
not be stored in fixed-point representation.

23
Storing Reals: Floating-Point Representation

• The solution for maintaining accuracy or precision is to use floating-point


representation.
• A floating-point representation of a number is made up of three parts: a sign, a shifter
and a fixed-point number.

Example: The following shows the decimal number 7,425,000,000,000,000,000,000.00


in scientific notation (floating-point representation).

Actual number à + 7 425 000 000 000 000 000 000.00

Scientific notation à + 7.425 x 1021


24
Storing Reals: Normalization, Sign, Exponent & Mantissa

• Normalization: to make the fixed part of the representation uniform, both the
scientific method (for the decimal system) & the floating-point method (for the
binary system) use only one non-zero digit on the left of the decimal point.
• Sign: can be stored using 1 bit
• Exponent: The exponent (power of 2) defines the shifting of the decimal point.
• Mantissa: is a fractional part that, together with the sign, is treated like an integer
stored in sign-and-magnitude representation.

Sign Exponent Mantissa


+ 2" × 1.0001110101
1 6 1.0001110101
25
Storing Floating-Point Numbers using IEEE standards

Two most common standards for storing floating-point numbers: Single precision
(Excess_27), and Double precision (Excess_1023).

the bits to the


right of the
decimal point

Figure 3.8. IEEE standards for floating-point representation


26
Storing Floating-Point Numbers using IEEE standards

A real number is stored using these steps: Show the Excess_127 (single precision)
representation of the decimal number 5.75.
1. Store the sign in S (0 or 1). 1. S=0

2. Change the number to binary. 2. 101.11

3. Normalize. 3. 1.0111 x 22

4. Find the values of E and M. 4. E = 2 + 127 = 129 = (10000001)! ;


M = 0111, but need to append 19 0s to make 23
5. Concatenate S, E, and M.
5.
S E M
0 10000001 01110000000000000000000
27
Retrieving Floating-Point Numbers using IEEE standards

A real number is stored using these steps: (110010100 00000000111000100001111)# is stored


in memory in Excess_127 format à (? )!"
1. Find the value of S, E, M
1. S E M
1 10010100 00000000111000100001111

2. If S = 0, set the sign to positive, otherwise,


2. S = 1 à sign = negative
set the sign to negative
3. E = 10010100! − 127 = 148 − 127 = 21
3. Find the shifter (E – 127)
4. 1.00000000111000100001111! ×2!# =
4. De-normalize the mantissa.
1000000001110001000011.11!
5. Change the denormalized number to binary
5. Covert (4) to decimal: 2104387.75
to find the absolute value.
6. Add the sign: −2104387.75
6. Add the sign.
28
CONTENT

1. Data types

2. Storing Numbers

3. Storing Text, Audio, Image, Video

29
3.1 Storing Text

A section of text in any language is a sequence of symbols used to represent an idea in


that language.
o For example, the English language uses 26 symbols (A, B, C,…, Z) to represent uppercase letters,
26 symbols (a, b, c, …, z) to represent lowercase letters, nine symbols (0, 1, 2, …, 9) to represent
numeric characters and symbols (., ?, :, ; , …, !) to represent punctuation.
o Other symbols such as blank, newline, and tab are used for text alignment and readability.

Representing symbols using bit patterns


We can represent each symbol with a bit pattern. In other words, text such as “CATS”, which is
made up from four symbols, can be represented as four 𝑛-bit patterns, each pattern defining a
single symbol.

30
Storing Text: Codes

• ASCII (American Standard Code of Information Interchange):


o ASCII: Using 7 bits for each symbol
o Extended ASCII: Using 8 bits for each symbol

• Unicode: Using 32 bits to represent up to 2$! symbols (including graphical and special
symbols). Suitable for the communication in multiple languages. ASCII and extended ASCII
are parts of Unicode.
• Other Codes

Number of symbols Bit pattern length Number of symbols Bit pattern length
2 1 128 7
4 2 257 8
8 3 65,536 16
16 4 4,294,967,296 32
Table 3.8. Number of symbols and bit pattern length
31
3.2 Storing Audio

Audio:
• is a representation of sound or music
• is not countable
• varies with time
• is an example of analog data. Even if we
are able to measure all its values in a
period of time, we cannot store these in Figure 3.9. An audio signal
the computer’s memory, as we would
need an infinite number of memory
locations.

32
Storing Audio: Sampling

If we cannot record all the values of an audio signal over an interval, we can record
some of them.
Sampling means that we select only a finite number of points on the analog signal,
measure their values, and record them.
A sampling rate of 𝟒𝟎, 𝟎𝟎𝟎 samples per second is generally good enough.

Figure 3.10. Sampling an audio signal


33
Storing Audio: Quantization

• The value measured for each sample is a real number. This means that we can store
40,000 real values for each one-second sample. However, it is simpler to use an unsigned
integer (a bit pattern) for each sample.
• Quantization refers to a process that rounds the value of a sample to the closest integer
value.
o For example, if the real value is 17.2 à 17; if the value is 17.7 à 18.

34
Storing Audio: Encoding

• The quantized sample values need to be encoded as bit patterns. Some


systems assign positive and negative values to samples, some just shift the
curve to the positive part and assign only positive values.
• Bit depth: the number of bits per sample
• If we call the bit depth 𝐵; the number of samples per second, 𝑆, we need to
store 𝑆 × 𝐵 bits for each second of audio. This product is referred to as bit
rate, 𝑅.
o For example, if we use 40,000 samples per second and 16 bits per each sample,
the bit rate is:
𝑅 = 40,000×16 = 640,000 𝑏𝑖𝑡𝑠 𝑝𝑒𝑟 𝑠𝑒𝑐𝑜𝑛𝑑 = 640 𝐾𝑏𝑠 𝑝𝑒𝑟 𝑠𝑒𝑐𝑜𝑛𝑑

35
Storing Audio: Standards for Sound Encoding

• Today the dominant standard for storing audio is MP3 (short for MPEG Layer 3).
• This standard is a modification of the MPEG (Motion Picture Experts Group)
compression method used for video. It uses 44,100 samples per second and 16
bits per sample.
• The result is a signal with a bit rate of 705,600 bits per second, which is
compressed using a compression method that discards information that cannot
be detected by the human ear. This is called lossy compression, as opposed to
lossless compression.

36
3.3 Storing Images

Images are stored using two different techniques: raster graphics and vector graphics

Raster graphics
• Raster graphics (or bitmap graphics) is used to store an analog image (e.g., a photograph).
o A photograph consists of analog data, similar to audio information. The difference is that the
intensity (color) of data varies in space instead of in time.

à Data must be sampled. Sampling in this case is normally called scanning. The samples are
called pixels (picture elements).
• Resolution: in image scanning we need to decide how many pixels we should record for each
square or linear inch. The scanning rate in image processing is called resolution.

37
Color
Color Depth : The number of bits used to represent a pixel, depends on how the pixel’s color is
handled by different encoding techniques. The perception of color is how our eyes respond to a
beam of light.
• True-Color: a technique used to encode a
pixel is called True- Color, which uses 24
bits to encode a pixel

• Indexed Color: The indexed color—or


palette color — scheme uses only a portion
of these colors

38
Standards for Image Encoding

• Several de-facto standards for image encoding are in use.


• JPEG (Joint Photographic Experts Group) uses the True- Color scheme, but
compresses the image to reduce the number of bits.
• GIF (Graphic Interchange Format), on the other hand, uses the indexed color
scheme.
• Software: Photoshop, PhotoImpact, Corel Painter

39
Vector Graphics

• Raster graphics has two disadvantages: the file size is big, and rescaling is troublesome.
• The vector graphic image encoding method does not store the bit patterns for each pixel. An
image is decomposed into a combination of geometrical shapes such as lines, squares or
circles.
• For example, consider a circle of radius r. The main pieces of information a program needs to
draw this circle are:
1. The radius r and equation of a circle
2. The location of the center point of the circle
3. The stroke line style and color
4. The fill style and color

• Standards: SVG, EPS, WMF, AI, CDR


• Software: Inkscape, Illustrator, CorelDRAW
40
3.4 Storing Video

• Video is a representation of images (called frames) over time.


• A movie consists of a series of frames shown one after another to create the illusion of
motion.
• In other words, video is the representation of information that changes in space (single
image) and in time (a series of images).
• Each image or frame is transformed into a set of bit patterns and stored à The
combination of the images then represents the movie

41
3.2 Operations on
Data
Content

• Logic

• Shift

• Arithmetic operations

43
Objectives

After studying this chapter, the student should be able to:


• List the three categories of operations performed on data.
• Perform unary and binary logic operations on bit patterns.
• Distinguish between logic and arithmetic shift operations.
• Perform addition and subtraction on integers when they are stored in two’s complement format.
• Perform addition and subtraction on integers when stored in sign-and-magnitude format.
• Perform addition and subtraction operations on reals stored in floating-point format.

44
CONTENT

• NOT
• Logic
• AND
• OR
• Shift
• XOR
• Arithmetic operations

45
LOGIC operations: Introduction

• LOGIC operations refer to those operations that


apply the same basic operation on individual bits
of a pattern, or on two corresponding bits in two
patterns.
• A logic operation at the pattern level is 𝑛 logic
operations, of the same type, at the bit level
where 𝑛 is the number of bits in the pattern.
• A bit can take one of the two values: 0 or 1. If we
interpret 0 as the value false and 1 as the value
true, we can apply the operations defined in
Boolean algebra to manipulate bits
Figure 3.11. Logic operations

46
LOGIC operations: NOT operator

The NOT operator is a unary operator: it takes only one input. The output bit is
the complement of the input.

Example: Use the NOT operator on the bit pattern 10011000.


Solution The solution is shown below. Note that the NOT operator changes every 0 to
1 and every 1 to 0.

NOT 1 0 0 1 1 0 0 0 Input
0 1 1 0 0 1 1 1 Output

47
LOGIC operations: AND operator

The AND operator is a binary operator: it takes two inputs. The output bit is 1 if
both inputs are 1s and the output is 0 in the other three cases.

Example: Use the AND operator on the bit patterns 10011000 and 00101010.
Solution: The solution is shown below:

AND 1 0 0 1 1 0 0 0 Input 1
0 0 1 0 1 0 1 0 Input 2
0 0 0 0 1 0 0 0 Output

For 𝑥 = 0 or 1 𝑥 AND 0 → 0 and 0 AND 𝑥 → 0

48
LOGIC operations: OR operator

The OR operator is a binary operator: it takes two inputs. The output bit is 0 if
both inputs are 0s and the output is 1 in other three cases.

Example: Use the OR operator on the bit patterns 10011001 and 00101110.
Solution: The solution is shown below:

OR 1 0 0 1 1 0 0 1 Input 1
0 0 1 0 1 1 1 0 Input 2
1 0 1 1 1 1 1 1 Output

For 𝑥 = 0 or 1 𝑥 OR 1 → 1 and 1 OR 𝑥 → 1

49
LOGIC operations: XOR operator

The XOR operator is a binary operator like the OR operator, with only one
difference: the output is 0 if both inputs are 1s.

Example: Use the XOR operator on the bit patterns 10011001 and 00101110
Solution: The solution is shown below:

XOR 1 0 0 1 1 0 0 1 Input 1
0 0 1 0 1 1 1 0 Input 2
1 0 1 1 0 1 1 1 Output

50
CONTENT

• Logic

• Shift • Logical
o Simple
• Arithmetic operations o Circular
• Arithmetic

51
SHIFT operations: Introduction

• SHIFT operations move the bits in a pattern, changing the positions of the bits.
They can move bits to the left or to the right.
• Two categories: logical shift operations & arithmetic shift operations.
• Logical shift: A logical shift operation is applied to a pattern that does not
represent a signed number.
• Because these shift operations may change the sign of the number that is defined
by the leftmost bit in the pattern. Two types of logical shift operations:
• Simple shift
• Circular shift (Rotate)

52
SHIFT operations: Logical Right/Left Simple Shift

Figure 3.12 Simple shift operations

Example: Use a logical left shift operation on the bit pattern 10011000.

Solution
The leftmost bit is lost and a 0 is inserted as the rightmost bit.

53
SHIFT operations: Logical Right/Left Circular Shift

Figure 3.13. Circular shift operations

Example: Use a circular left shift operation on the bit pattern 10011000.

Solution
The solution is shown below. The leftmost bit is circulated and becomes the rightmost bit.

54
4. Arithmetic Shift Operations

Arithmetic shift operations assume that the bit pattern is a signed integer in two’s
complement format. Arithmetic right shift: divide an integer by two; arithmetic left shift:
multiply an integer by two.

Figure 3.14. Arithmetic shift operations

Example: Use an arithmetic right shift operation on the bit pattern 10011001. The pattern is an
integer in two’s complement format.
Solution: The solution is shown below

-103

-52 55
CONTENT

• Logic

• Shift

• Arithmetic operations

56
Introduction

Arithmetic operations: +, −, × and ÷. These can be applied to integers and floating-point


numbers.

Arithmetic Operations on Integers


• All arithmetic operations such as +, −, × and ÷ can be applied to integers. Although
multiplication (division) of integers can be implemented using repeated addition (subtraction),
the procedure is not efficient.

Addition and subtraction for two’s complement integers


• When the subtraction operation is encountered, the computer simply changes it to an addition
operation, but makes two’s complement of the second number.

𝐴 − 𝐵 ↔ 𝐴 + 𝐵E + 1 where ( 𝐵E + 1 ) means the two’s complement of 𝐵


57
Addition and subtraction of integers in two’s complement

Figure 3.15. Addition and subtraction of integers in two’s complement format


58
Addition and subtraction of integers in two’s complement (cont.)

Example: Two integers A and B are stored in two’s complement format. Show how B is
added to A.
𝐴 = (00010001)$ 𝐵 = (00010110)$

Solution: The operation is adding. A is added to B and the result is stored in R.


(+17) + (+22) = (+39).

1 Carry
0 0 0 1 0 0 0 1 A
+ 0 0 0 1 0 1 1 0 B
0 0 1 0 0 1 1 1 R

59
Addition and subtraction of integers in sign-and-magnitude

Figure 3.16. Addition and subtraction of integers in sign-and-magnitude 60


Addition and subtraction of integers in sign-and-magnitude (cont.)

Example: Two integers A and B are stored in sign-and-magnitude format. Show how B is
subtracted from A.
A = (𝟏 1010001), B = (𝟏 0010110),
Solution
The operation is subtracting: 𝐵- = 𝐵- = 0. 𝑆 = (𝐴- 𝑋𝑂𝑅 𝐵- ) = (1 𝑋𝑂𝑅 0) = 1.
𝑅. = 𝐴. + (𝐵. + 1). There’s an overflow à 𝑅. is final.

Check in decimals: −81 − −22 = −59


61
Arithmetic Operations on Reals

• All arithmetic operations such as addition, subtraction, multiplication and division can be applied
to reals stored in floating-point format.
• Multiplication of two reals involves multiplication of two integers in sign-and-magnitude
representation.
• Division of two reals involves division of two integers in sign-and-magnitude representations

Addition and Subtraction of Reals


• Addition and subtraction of real numbers stored in floating-point numbers is reduced to addition
and subtraction of two integers stored in sign-and-magnitude (combination of sign and mantissa)
after the alignment of decimal points. Figure 3.17 shows a simplified version of the procedure
(there are some special cases that we have ignored).

62
Addition and subtraction of reals in floating-point format

Figure 3.17. Addition and subtraction of


integers in floating-point format
63
Addition and subtraction of reals in floating-point format (cont.)

Example
Show how the computer finds the result of (+5.75) + (+161.875) = (1167.625).
Solution
These two numbers can be stored in floating-point format, as shown below:

De-normalize: adding the hidden 1s to the mantissa & incrementing the exponent

64
Addition and subtraction of reals in floating-point format (cont.)

Align the mantissas: increment the first exponent & shift its mantissa to the right

Do sign-and-magnitude addition on the signs & mantissas:

65
Addition and subtraction of reals in floating-point format (cont.)

There is no overflow in the mantissa, so we normalize:

The mantissa is only 23 bits, no rounding is needed.


𝐸 = (10000110)! = 134
𝑀 = 0100111101.

In other words, the result is:


(1.0100111101)! × 2#$%–#!' = (10100111.101)! = 167.625.

66

You might also like