Chapter 4. Operations on Data (4-1 Logic Operations (At Bit Level (Binary…
Operations on Data
4-1 Logic Operations
A logic operation at the pattern level is n logic operations
of the same type, at the bit level where n is the number
of bits in the pattern.
At Bit Level
Binary (two inputs)
In English we use the conjunction “or” sometimes to mean an inclusive-or, and sometimes to means an exclusive-or.
Unary (one input)
At Pattern Level
The four logic operations can be used to modify a bit pattern: Complementing (NOT), Unsetting (AND),
Setting (OR), Flipping (XOR).
A mask is a bit pattern that is applied to a target bit
pattern to achieve a specific result.
4-2 Shift Operations
Logical Shift Operations (unsigned shift)
Circular Shift (rotate)
Arithmetic Shift Operations (signed shift)
Right shift is used to divide an integer by two.
Left shift is used to multiply an integer by two.
4-3 Arithmetic Operations
Although multiplication (division) of integers can be implemented using repeated addition (subtraction),
the procedure is not efficient.
Arithmetic on Floating-point Number
(Steps for Addition and Subtraction)
Check the signs
If the signs are the same,
add the numbers and assign the sign to the result
If the signs are different, compare the absolute values,
subtract the smaller from the larger,
and use the sign of the larger for the result
Move the decimal points to make the
exponents the same (as larger exponent).
Add or subtract the mantissas
Normalize the result before storing in memory
Check for any overflow