Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Division - Arithmetic Operations, Computer Science and IT Engineering

Division - Arithmetic Operations, Computer Science and IT Engineering - Computer Science Engineering (CSE) PDF Download

Arithmetic Operations: Division

The reciprocal operation of multiply is divide, an operation that is even less frequent and even more quirky.

DIVISION

The reciprocal operation of multiply is divide, an operation that is even less frequent and even more quirky.

Division - Arithmetic Operations, Computer Science and IT Engineering - Computer Science Engineering (CSE)

It even offers the opportunity to perform a mathematically invalid operation: dividing by 0. The example is dividing 1,001,010 by 1000. The two operands (dividend and divisor) and the result (quotient) of divide are accompanied by a second result called the remainder. Here is another way to express the relationship between the components:

Division - Arithmetic Operations, Computer Science and IT Engineering - Computer Science Engineering (CSE)

Fig. 2.8 First version of the Division hardware

Dividend = Quotient *  Divisor + Remainder

where the remainder is smaller than the divisor. Infrequently, programs use the divide instruction just to get the remainder, ignoring the quotient. The basic grammar school division algorithm tries to see how big a number can be subtracted, creating a digit of the quotient on each attempt. Binary numbers contain only 0 or 1, so binary division is restricted to these two choices, thereby simplifying binary division. If both the dividend and divisor are positive and hence the quotient and the remainder are nonnegative. The division operands and both results are 32-bit values.

A Division Algorithm and Hardware

Initially, the 32-bit Quotient register set to 0. Each iteration of the algorithm needs to move the divisor to the right one digit, start with the divisor placed in the left half of the 64-bit Divisor register and shift it right 1 bit each step to align it with the dividend. The Remainder register is initialized with the dividend. Figure shows three steps of the first division algorithm.

Unlike a human, the computer isn’t smart enough to know in advance whether the divisor is smaller than the dividend. It must first subtract the divisor in step 1; If the result is positive, the divisor was smaller or equal to the dividend, so generate a 1 in the quotient (step 2a). If the result is negative, the next step is to restore the original value by adding the divisor back to the remainder and generate a 0 in the quotient (step 2b). The divisor is shifted right and then iterate again. The remainder and quotient will be found in their namesake registers after the iterations are complete.

The following figure shows three steps of the first division algorithm. Unlike a human, the computer isn’t smart enough to know in advance whether the divisor is smaller than the

dividend.
Division - Arithmetic Operations, Computer Science and IT Engineering - Computer Science Engineering (CSE)

Fig. 2.9 Division Algorithm

 

It must first subtract the divisor in step 1; remember that this is how we performed the comparison in the set on less than instruction. If the result is positive, the divisor was smaller or equal to the dividend, so we generate a 1 in the quotient (step 2a). If the result is negative, the next step is to restore the original value by adding the divisor back to the remainder and generate a 0 in the quotient (step 2b). The divisor is shifted right and then we iterate again. The remainder and quotient will be found in their namesake registers after the iterations are complete.

Using a 4-bit version of the algorithm to save pages, let’s try dividing 710 by 210, or 0000 01112 by 00102.

Division - Arithmetic Operations, Computer Science and IT Engineering - Computer Science Engineering (CSE)

Fig. 2.10 Values of register in division algorithm

The above figure shows the value of each register for each of the steps, with the quotient being 3ten and the remainder 1ten. Notice that the test in step 2 of whether the remainder is positive or negative simply tests whether the sign bit of the Remainder register is a 0 or 1. The surprising requirement of this algorithm is that it takes n + 1 steps to get the proper quotient and remainder.

This algorithm and hardware can be refined to be faster and cheaper. The speedup comes from shifting the operands and the quotient simultaneously with the subtraction. This refinement halves the width of the adder and registers by noticing where there are unused portions of registers and adders.

SIGNED DIVISION

The one complication of signed division is that we must also set the sign of the remainder. Remember that the following equation must always hold:

Dividend = Quotient × Divisor + Remainder

To understand how to set the sign of the remainder, let’s look at the example of dividing all the combinations of ±7 10 by ±2 10.

The first case is easy:

+7 ÷ +2: Quotient = +3, Remainder = +1 Checking the results:

7 = 3 × 2 + (+1) = 6 + 1

If we change the sign of the dividend, the quotient must change as well:

–7 ÷ +2: Quotient = –3

Rewriting our basic formula to calculate the remainder:

Remainder = (Dividend – Quotient × Divisor) = –7 – (–3 × +2) = –7–(–6) = –1

So,

–7 ÷ +2: Quotient = –3, Remainder = –1

Checking the results again:

–7 = –3 × 2 + ( –1) = – 6 – 1

The following figure shows the revised hardware.

Division - Arithmetic Operations, Computer Science and IT Engineering - Computer Science Engineering (CSE)

Fig. 2.11 Division hardware

The reason the answer isn’t a quotient of –4 and a remainder of +1, which would also fit this formula, is that the absolute value of the quotient would then change depending on the sign of the dividend and the divisor! Clearly, if

Division - Arithmetic Operations, Computer Science and IT Engineering - Computer Science Engineering (CSE)

programming would be an even greater challenge. This anomalous behavior is avoided by following the rule that the dividend and remainder must have the same signs, no matter what the signs of the divisor and quotient. We calculate the other combinations by following the same rule:

Division - Arithmetic Operations, Computer Science and IT Engineering - Computer Science Engineering (CSE)

Thus the correctly signed division algorithm negates the quotient if the signs of the operands are opposite and makes the sign of the nonzero remainder match the dividend.

Faster Division

Many adders can be used to speed up multiply, cannot be used to do the same trick for divide. The reason is that it is needed to know the sign of the difference before performing the next step of the algorithm, whereas with multiply we could calculate the 32 partial products immediately.

There are techniques to produce more than one bit of the quotient per step. The SRT division technique tries to guess several quotient bits per step, using a table lookup based on the upper bits of the dividend and remainder. It relies on subsequent steps to correct wrong guesses. A typical value today is 4 bits. The key is guessing the value to subtract. With binary division, there is only a single choice.

These algorithms use 6 bits from the remainder and 4 bits from the divisor to index a table that determines the guess for each step. The accuracy of this fast method depends on having proper values in the lookup table.

 

Restoring and non restoring division algorithm

  • Assume ─ X register k-bit dividend

  • Assume ─ Y the k-bit divisor

  • Assume ─ S a sign-bit

1. Start: Load 0 into accumulator k-bit A and dividend X is loaded into the k-bit quotient register MQ.

2. Step A : Shift 2 k-bit register pair A -MQ left

3. Step B: Subtract the divisor Y from A.

4. Step C: If sign of A (msb) = 1, then reset MQ 0 (lsb) = 0 else set = 1.

5. Steps D: If MQ 0 = 0 add Y (restore the effect of earlier subtraction).

6. Steps A to D repeat again till the total number of cyclic operations = k. At the end, A has the remainder and MQ has the

Division - Arithmetic Operations, Computer Science and IT Engineering - Computer Science Engineering (CSE)

Fig. 2.12 Division of 4-bit number by 7-bit dividend

Division using Non-restoring Algorithm

  • Assume ─ that there is an accumulator and MQ register, each of k-bits • MQ 0, (lsb of MQ) bit gives the quotient, which is saved after a subtraction or addition

  • Total number of additions or subtractions are k-only and total number of shifts = k plus one addition for restoring remainder if needed

  • Assume ─ that X register has (2 k−1) bit for dividend and Y has the k-bit divisor

  •  Assume ─ a sign-bit S shows the sign

1. Load (upper half k −1 bits of the dividend X) into accumulator k-bit A and load dividend X (lower half bits into the lower k bits at quotient register MQ

  • Reset sign S = 0

  •  Subtract the k bits divisor Y from S-A (1 plus k bits) and assign MQ 0 as per S

2. If sign of A, S = 0, shift S plus 2 k-bit register pair A-MQ left and subtract the k bits divisor Y from S-A (1 plus k bits); else if sign of A, S = 1, shift S plus 2 k-bit register pair A - MQ left and add the divisor Y into S-A (1 plus k bits)

  • Assign MQ 0 as per

Division - Arithmetic Operations, Computer Science and IT Engineering - Computer Science Engineering (CSE)

Fig. 2.13 Division using Non-restoring Algorithm

3. Repeat step 2 again till the total number of operations = k.

4. If at the last step, the sign of A in S = 1, then add Y into S -A to leave the correct remainder into A and also assign MQ 0 as per S, else do nothing.

5. A has the remainder and MQ has the quotient

 
The document Division - Arithmetic Operations, Computer Science and IT Engineering - Computer Science Engineering (CSE) is a part of Computer Science Engineering (CSE) category.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)

Top Courses for Computer Science Engineering (CSE)

FAQs on Division - Arithmetic Operations, Computer Science and IT Engineering - Computer Science Engineering (CSE)

1. What are the basic arithmetic operations involving division?
Ans. The basic arithmetic operations involving division are: - Division: It is the process of splitting a number into equal parts. For example, dividing 10 by 2 gives the result 5. - Quotient: It is the result obtained after dividing one number by another. For example, the quotient of dividing 10 by 2 is 5. - Remainder: It is the amount left over after dividing one number by another. For example, dividing 10 by 3 gives a quotient of 3 and a remainder of 1. - Dividend: It is the number that is being divided. In the division operation 10 ÷ 2, 10 is the dividend. - Divisor: It is the number by which the dividend is divided. In the division operation 10 ÷ 2, 2 is the divisor.
2. What is the significance of division in computer science and IT engineering?
Ans. Division plays a significant role in computer science and IT engineering. Some of its important applications include: - Data partitioning: Division is used to divide large sets of data into smaller partitions, which can be distributed across multiple machines or servers. This helps in improving the performance and efficiency of data processing. - Algorithm design: Many algorithms in computer science and IT engineering involve the use of division. For example, the binary search algorithm uses division to find the middle element of a sorted array. - Error correction: Division is used in error correction codes to detect and correct errors in data transmission. Techniques like cyclic redundancy check (CRC) use division to generate error-detecting codes. - Performance optimization: Division operations can be computationally expensive, especially on resource-constrained devices. In certain cases, division can be replaced with multiplication or bitwise operations to improve performance. - Network addressing: In computer networks, division is used to divide IP addresses into network addresses and host addresses. This division helps in routing data packets efficiently across the network.
3. How does division work in computer arithmetic?
Ans. Division in computer arithmetic follows the same principles as division in traditional arithmetic. However, there are a few important differences to consider: - Integer division: In computer arithmetic, division involving integers may result in an integer quotient and a remainder. This means that the result is rounded down to the nearest integer. For example, dividing 10 by 3 in computer arithmetic would yield a quotient of 3 and a remainder of 1. - Floating-point division: Division involving floating-point numbers in computer arithmetic follows the rules of real number division. It provides a more precise result, including decimal places. For example, dividing 10.0 by 3.0 in computer arithmetic would yield a quotient of approximately 3.333. - Division by zero: Dividing any number by zero is undefined in mathematics. In computer arithmetic, division by zero often results in an error or an undefined value. It is important to handle such cases carefully to prevent program crashes or unexpected behavior. - Overflow and underflow: Division operations can also lead to overflow or underflow errors when the result exceeds the maximum or minimum representable value. These errors should be handled to ensure correct computation.
4. How can division be implemented in computer programs?
Ans. Division can be implemented in computer programs using various techniques and algorithms. Some common approaches include: - Long division: Long division is a manual method of division that can be adapted for computer programs. It involves dividing the dividend by the divisor digit by digit and calculating the quotient and remainder at each step. - Bitwise division: Division can be performed using bitwise operations, such as shifting and XOR. These operations are particularly useful for division by powers of two, where the divisor is a binary number with only a single set bit. - Newton-Raphson method: The Newton-Raphson method is an iterative approach to compute the reciprocal of a number, which can be used for division. By finding the reciprocal of the divisor and multiplying it with the dividend, division can be achieved. - Library functions: Most programming languages provide built-in library functions or operators for division. These functions are optimized for performance and accuracy and can be directly used in programs. The choice of implementation depends on factors such as the programming language, the specific requirements of the program, and the performance considerations.
5. What are the limitations and challenges of division in computer science and IT engineering?
Ans. Division in computer science and IT engineering comes with certain limitations and challenges, including: - Precision and rounding errors: Division involving floating-point numbers can introduce precision and rounding errors due to the finite representation of real numbers in computers. These errors can accumulate and impact the accuracy of computations. - Performance impact: Division operations are generally slower compared to other arithmetic operations, especially on resource-constrained devices. Careful consideration should be given to optimize division-intensive algorithms and minimize their usage when possible. - Division by zero errors: Dividing any number by zero is undefined in mathematics, and division by zero errors can lead to program crashes or unexpected behavior. Proper error handling and validation are essential to prevent such errors. - Overflow and underflow: Division operations can result in overflow or underflow errors when the result exceeds the maximum or minimum representable value. These errors should be accounted for and handled appropriately to avoid incorrect results. - Algorithm complexity: Some division algorithms, such as long division, can be complex and require additional computational resources. Efficient algorithm design and implementation are necessary to minimize the computational overhead. Addressing these limitations and challenges requires a good understanding of the underlying principles of division and careful consideration of the specific requirements of the computer science and IT engineering applications.
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Free

,

MCQs

,

practice quizzes

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

shortcuts and tricks

,

Division - Arithmetic Operations

,

Objective type Questions

,

Important questions

,

Summary

,

mock tests for examination

,

Extra Questions

,

Previous Year Questions with Solutions

,

Sample Paper

,

pdf

,

Viva Questions

,

video lectures

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

Division - Arithmetic Operations

,

Semester Notes

,

Division - Arithmetic Operations

,

Computer Science and IT Engineering - Computer Science Engineering (CSE)

,

ppt

,

Exam

,

past year papers

,

study material

;