0% found this document useful (0 votes)
30 views53 pages

Chap04 1473751047 598102

Chapter 4 discusses operations on data, focusing on logic operations at the bit and pattern levels, including NOT, AND, OR, and XOR. It also covers logical and arithmetic shift operations, as well as arithmetic operations on integers and reals in various formats. The chapter highlights the importance of understanding these operations for manipulating data effectively in computing.

Uploaded by

Hòa Mai
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)
30 views53 pages

Chap04 1473751047 598102

Chapter 4 discusses operations on data, focusing on logic operations at the bit and pattern levels, including NOT, AND, OR, and XOR. It also covers logical and arithmetic shift operations, as well as arithmetic operations on integers and reals in various formats. The chapter highlights the importance of understanding these operations for manipulating data effectively in computing.

Uploaded by

Hòa Mai
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/ 53

CHAPTER 4

Operation on Data
q List the three categories of operations performed on data.
q Perform unary and binary logic operations on bit patterns.
q Distinguish between logic shift operations and arithmetic
shift operations.
q Perform logic shift operations on bit patterns.
q Understand some applications of logic and shift operations such
as setting, unsetting, and flipping bits.
q Perform arithmetic shift operation on integers whey they are
stored in two’ complement format.
q Perform addition and subtraction operations on reals when they
are stored in sign and magnitude format.
4.1.1 Logic operations at bit level
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.
Boolean algebra, named in honor of George Boole, belongs
to a special field of mathematics called logic. Boolean
algebra and its application to building logic circuits in
computers are briefly discussed in Appendix E. In this
section, we show briefly four bit-level operations that are
used to manipulate bits: NOT, AND, OR, and XOR.

Boolean algebra and logic circuits are discussed in


Appendix E.
Figure 4.1 Logic operations at the bit level
NOT
The NOT operator is a unary operator: it takes only one
input. The output bit is the complement of the input.

AND
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.

For x = 0 or 1 x AND 0 → 0 0 AND x → 0


OR
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.

For x = 0 or 1 x OR 1 → 1 1 OR x → 1

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

For x = 0 or 1 1 XOR x → NOTx 1 XOR x → 1


Example 4.1
Example 4.2

x XOR y ↔ [x AND (NOT y)] OR [(NOT x) AND y]

4.9
4.1.2 Logic operations at pattern level
The same four operators (NOT, AND, OR, and XOR) can be
applied to an n-bit pattern. The effect is the same as applying
each operator to each individual bit for NOT and to each
corresponding pair of bits for other three operators. Figure
4.2 shows these four operators with input and output
patterns.

Figure 4.2 Logic operators applied to bit patterns


Example 4.3

4.11
Example 4.4

4.12
Example 4.5

4.13
Example 4.6

4.14
Applications

The four logic operations can be used to modify a bit pattern.

q Complementing (NOT)

q Unsetting (AND)

q Setting (OR)

q Flipping (XOR)

4.15
Example 4.7

4.16
Example 4.8

4.17
Example 4.9

4.18
4.19
4.2.1 Logical shift operations
A logical shift operation is applied to a pattern that does not
represent a signed number. The reason is that these shift
operation may change the sign of the number that is defined
by the leftmost bit in the pattern. We distinguishes two types
of logical shift operations, as described below:

q Logical shift

q Logical circular shift (Rotate)

4.20
Figure 4.3 Logical shift operations

4.21
Example 4.10

Discarded

Added

4.22
Figure 4.4 Circular shift operations

4.23
Example 4.11
4.2.2 Arithmetic shift operations
Arithmetic shift operations assume that the bit pattern is a
signed integer in two’s complement format. Arithmetic right
shift is used to divide an integer by two, while arithmetic left
shift is used to multiply an integer by two.

Figure 4.5 Arithmetic shift operations

4.25
Example 4.12

4.26
Example 4.13

4.27
Example 4.14

4.28
Example 4.15

4.29
4.30
4.3.1 Arithmetic operations on integers
All arithmetic operations such as addition, subtraction,
multiplication, and division can be applied to integers.
Although multiplication (division) of integers can be
implemented using repeated addition (subtraction), the
procedure is not efficient. There are more efficient
procedures for multiplication and division, such as Booth
procedures, but these are beyond the scope of this book. For
this reason, we only discuss addition and subtraction of
integers here.

4.31
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. In other words:

A − B ↔ A + (B + 1)

Where B is the one’s complement of B and


(B + 1) means the two’s complement of B

4.32
We should remember that we add integers column by
column. The following table shows the sum and carry (C).

4.33
Figure 4.6 Addition and subtraction of integers in two’s complement
Example 4.16

4.35
Example 4.17

4.36
Example 4.18

4.37
Example 4.19

4.38
Example 4.20

4.39
When we do arithmetic operations on numbers in a
computer, we should remember that each number
and the result should be in the range defined by
the bit allocation.
sign-and-magnitude integers
Addition and subtraction for integers in sign-and-magnitude
representation looks very complex. We have four different
combination of signs (two signs, each of two values) for
addition, and four different conditions for subtraction. This
means that we need to consider eight different situations.
However, if we first check the signs, we can reduce these
cases, as shown in Figure 4.7.

4.41
4.42
Example 4.22

4.43
Example 4.23

4.44
4.3.2 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. Since we did
not discuss the multiplication or division of integers in sign-
and magnitude representation, we will not discuss the
multiplication and division of reals, and only show addition
and subtractions for reals.

4.45
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
4.8 shows a simplified version of the procedure (there are
some special cases that we have ignored).

4.46
4.47
Example 4.23

4.48
4.49
4.50
Example 4.24

4.51
4.52
4.53

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy