0% found this document useful (0 votes)
13 views

Algorithms-Unit 5 CO

Uploaded by

shaikkalesha6194
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Algorithms-Unit 5 CO

Uploaded by

shaikkalesha6194
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

In computer organization, the addition of two numbers can be implemented using various

algorithms and methods. Here’s a basic overview of a common approach: the binary addition
algorithm.
Binary Addition Algorithm
1. Binary Representation: First, the numbers to be added are converted into binary
form. For example, the decimal numbers 3 and 5 are represented as 0011 and 0101 in
4-bit binary.
2. Addition Process: The addition is performed bit by bit from the least significant bit
(LSB) to the most significant bit (MSB), using the following rules:
o 0 + 0 = 0 (no carry)
o 0 + 1 = 1 (no carry)
o 1 + 0 = 1 (no carry)
o 1 + 1 = 10 (0 with a carry of 1)
3. Carry Handling: If a carry is generated from a sum (e.g., 1 + 1), it is added to the
next higher bit in the next column.
4. Final Result: The final result is obtained by concatenating the sums and any
remaining carry.
Example
Let’s add the binary numbers 0011 (3) and 0101 (5):
yaml
Copy code
0011
+ 0101
------
 Column 1 (LSB): 1 + 1 = 10 → Write down 0, carry 1
 Column 2: 1 + 0 + carry(1) = 10 → Write down 0, carry 1
 Column 3: 0 + 1 + carry(1) = 10 → Write down 0, carry 1
 Column 4 (MSB): 0 + 0 + carry(1) = 01 → Write down 1
So, the result is 1000, which is 8 in decimal.
Hardware Implementation
In hardware, binary addition is typically implemented using:
 Full Adders: These components perform the addition of three bits (two significant
bits and a carry from the previous column). They can be combined to form an adder
circuit.
 Ripple Carry Adder: A series of full adders connected in a way that the carry output
of one adder is the carry input of the next. While simple, it can be slow for large
numbers due to carry propagation.
 Carry Lookahead Adder: A more advanced circuit that reduces delay by calculating
carries in advance rather than waiting for each bit to propagate.
In computer organization, subtraction can be performed using various algorithms and
techniques. One common approach is to use the method of complement arithmetic. Here's a
breakdown of how subtraction can be implemented:
1. Binary Subtraction Using Borrowing
Similar to decimal subtraction, binary subtraction can use a borrowing method. Here's the
basic process:
 Align the binary numbers.
 Subtract each bit starting from the least significant bit (LSB).
 If a bit in the minuend (the number from which another is subtracted) is smaller than
the corresponding bit in the subtrahend (the number being subtracted), borrow from
the next higher bit.
2. Two's Complement Method
This is a widely used method for performing subtraction in binary:
1. Find the Two's Complement of the Subtrahend:
o Invert all bits of the subtrahend (this is called the one's complement).
o Add 1 to the least significant bit (LSB) of the inverted number to get the two's
complement.
2. Add the Two's Complement to the Minuend:
o Perform binary addition of the minuend and the two's complement of the
subtrahend.
o If there is a carry out of the most significant bit (MSB), it can be ignored in the
case of fixed-width binary numbers.
3. Result Interpretation:
o If the result is negative (in a signed binary format), it is represented in two's
complement format.
Example
To subtract 5 (101 in binary) from 12 (1100 in binary):
1. Find the two's complement of 5:
o One's complement of 5 (101) → 010
o Add 1 → 011 (which is 3 in decimal)
2. Add this to 12:
o 1100 (12)
o
 0011 (two's complement of 5)
o

o 1111 (which is 7 in decimal)


Binary multiplication in computer organization is a fundamental operation that mirrors the
traditional decimal multiplication method but operates using binary digits (0s and 1s). Here's
an overview of how it works and some key concepts involved:
Basics of Binary Numbers
 Binary System: Uses only two digits, 0 and 1.
 Bit: A binary digit, either 0 or 1.
 Byte: Typically consists of 8 bits.
Multiplication Process
Binary multiplication follows a similar process to decimal multiplication:
1. Partial Products: Each bit of the multiplier (the number being multiplied) is used to
create a partial product, depending on whether it is 0 or 1.
o If the bit is 1, the multiplicand (the number you are multiplying) is added to
the result, shifted left according to the bit's position.
o If the bit is 0, no addition occurs for that bit.
2. Addition of Partial Products: Once all bits have been processed, the partial products
are summed to produce the final result.
Example: Multiplying 3 (11 in binary) by 2 (10 in binary)
csharp
Copy code
11 (which is 3 in decimal)
x 10 (which is 2 in decimal)
_____
00 (11 * 0, shifted 0 places)
+ 11 (11 * 1, shifted 1 place)
_____
110 (which is 6 in decimal)
Implementation in Computers
1. Shift and Add Method: This is a common algorithm where:
o The multiplicand is shifted left for each bit in the multiplier.
o Depending on the current bit, it may be added to an accumulator.
2. Hardware Implementations: Most modern CPUs implement binary multiplication
using dedicated hardware like:
o Multipliers: Specialized circuits that can perform multiplication faster than a
series of shifts and adds.
o Booth's Algorithm: A method for handling signed binary numbers and
optimizing the multiplication process by reducing the number of required
additions.
3. Floating Point Multiplication: Involves multiplying mantissas and adding
exponents, following IEEE 754 standards.
Key Points
 Binary multiplication is efficient and essential for various applications, including
arithmetic operations in CPUs.
 Understanding binary multiplication helps in grasping how computers perform more
complex operations and manage numerical data.
The binary division algorithm is similar to decimal long division but operates on binary
numbers. Here's a breakdown of how it works in the context of computer organization:
Steps for Binary Division
1. Setup:
o Identify the dividend (the number to be divided) and the divisor (the number
by which to divide).
o Align the dividend and divisor in binary form.
2. Initialization:
o Create a quotient initialized to 0 and a remainder initialized to the dividend.
3. Division Process:
o Align: Shift the divisor left to align with the most significant bit (MSB) of the
current remainder.
o Subtract: If the current remainder is greater than or equal to the divisor,
subtract the divisor from the remainder. If the remainder is less than the
divisor, write 0 in the quotient.
o Shift: Shift the quotient left by 1 (to make room for the next bit).
o Repeat the process until all bits of the dividend have been processed.
4. Finalization:
o The final quotient is obtained, and the last remainder is the result of the
division.
Example
Let's divide 10110210110_2101102 (22 in decimal) by 11211_2112 (3 in decimal):
1. Initial Setup:
o Dividend: 101101011010110
o Divisor: 111111
2. Process:
o Shift divisor: 111111 becomes 110110110 (aligned).
o Since 10110≥11010110 \geq 11010110≥110, subtract:
 10110−110=1000010110 - 110 = 1000010110−110=10000
(remainder).
 Write 1 in the quotient (now it’s 111).
o Shift again: 111111 to 110011001100.
o Since 10000≥110010000 \geq 110010000≥1100, subtract:
 10000−1100=010010000 - 1100 = 010010000−1100=0100
(remainder).
 Write 1 in the quotient (now it’s 111111).
o Shift divisor again to 110001100011000.
o Since 0100<110000100 < 110000100<11000, write 0 in the quotient (now it’s
110110110).
o Final shift, divisor remains 110001100011000 (cannot subtract anymore).
o Shift and finalize the remainder.
3. Results:
o Quotient: 110110110 (6 in decimal).
o Remainder: 100100100 (4 in decimal).
Applications in Computer Organization
 Arithmetic Logic Units (ALUs): ALUs implement binary division as part of
arithmetic operations.
 Microprocessors: Division is performed using specific instructions that utilize this
algorithm.
 Software: Many programming languages and compilers translate division operations
into binary division at the machine level.
This algorithm is foundational for understanding how binary division is executed at the
hardware level in computers.

You might also like