The Wayback Machine - https://web.archive.org/web/20240709051505/https://www.geeksforgeeks.org/computer-arithmetic-set-2/
Open In App

Computer Arithmetic | Set – 2

Last Updated : 19 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

  

FLOATING POINT ADDITION AND SUBTRACTION  
 

  • FLOATING POINT ADDITION

To understand floating point addition, first we see addition of real numbers in decimal as same logic is applied in both cases.

For example, we have to add 1.1 * 103 and 50.

We cannot add these numbers directly. First, we need to align the exponent and then, we can add significant.

After aligning exponent, we get 50 = 0.05 * 103

Now adding significant, 0.05 + 1.1 = 1.15

So, finally we get (1.1 * 103 + 50) = 1.15 * 103

Here, notice that we shifted 50 and made it 0.05 to add these numbers.

Now let us take example of floating point number addition

We follow these steps to add two numbers:  

1. Align the significant

2. Add the significant  

3. Normalize the result

Let the two numbers be  

x = 9.75  
y = 0.5625

Converting them into 32-bit floating point representation,

9.75’s representation in 32-bit format = 0 10000010 00111000000000000000000  

0.5625’s representation in 32-bit format = 0 01111110 00100000000000000000000

Now we get the difference of exponents to know how much shifting is required.  

(10000010 – 01111110)2 = (4)10

Now, we shift the mantissa of lesser number right side by 4 units.

Mantissa of 0.5625 = 1.00100000000000000000000

(note that 1 before decimal point is understood in 32-bit representation)

Shifting right by 4 units, we get 0.00010010000000000000000  

Mantissa of 9.75 = 1. 00111000000000000000000

Adding mantissa of both

0. 00010010000000000000000

+ 1. 00111000000000000000000

————————————————-

1. 01001010000000000000000

In final answer, we take exponent of bigger number

So, final answer consist of :

Sign bit = 0  

Exponent of bigger number = 10000010

Mantissa = 01001010000000000000000  

32 bit representation of answer = x + y = 0 10000010 01001010000000000000000

  • FLOATING POINT SUBTRACTION

Subtraction is similar to addition with some differences like we subtract mantissa unlike addition and in sign bit we put the sign of greater number.

Let the two numbers be  

x = 9.75  
y = – 0.5625

Converting them into 32-bit floating point representation

9.75’s representation in 32-bit format = 0 10000010 00111000000000000000000

– 0.5625’s representation in 32-bit format = 1 01111110 00100000000000000000000

Now, we find the difference of exponents to know how much shifting is required.

(10000010 – 01111110)2 = (4)10  
Now, we shift the mantissa of lesser number right side by 4 units.

Mantissa of – 0.5625 = 1.00100000000000000000000

(note that 1 before decimal point is understood in 32-bit representation)

Shifting right by 4 units, 0.00010010000000000000000  

Mantissa of 9.75= 1. 00111000000000000000000

Subtracting mantissa of both

0. 00010010000000000000000

– 1. 00111000000000000000000

————————————————

1. 00100110000000000000000

Sign bit of bigger number = 0

So, finally the answer = x – y = 0 10000010 00100110000000000000000  

last

This article has been contributed by Anuj Batham. 

In this continuation of the previous set, we will cover some more concepts and operations involved in computer arithmetic:

  1. Signed vs. unsigned numbers: In computer arithmetic, numbers can be either signed or unsigned. Unsigned numbers only represent positive values, while signed numbers can represent both positive and negative values. Signed numbers are typically represented using two’s complement notation.
  2. Shift operations: Shift operations are used to move the bits of a number left or right. A left shift multiplies the number by 2 raised to the power of the number of shifted bits, while a right shift divides the number by 2 raised to the power of the number of shifted bits.
  3. Logical vs. arithmetic shifts: Shift operations can be either logical or arithmetic. Logical shifts insert zeros into the vacant bit positions, while arithmetic shifts preserve the sign bit when shifting a signed number.
  4. Carry and borrow: In addition and subtraction operations, carry and borrow refer to the bit that is carried over or borrowed from the next digit position when the result of an operation exceeds the number of bits available.
  5. Boolean algebra: Boolean algebra is a branch of mathematics that deals with logical operations on binary variables. It is widely used in computer arithmetic for operations such as bitwise AND, OR, and XOR.
  6. Fixed-point arithmetic: Fixed-point arithmetic is used to perform arithmetic operations on numbers with a fixed number of decimal places. It is commonly used in applications such as digital signal processing.
  7. Division algorithms: There are various algorithms used to perform division in computer arithmetic, including the restoring division algorithm, non-restoring division algorithm, and SRT division algorithm.
  8. Multiplication algorithms: There are also various algorithms used to perform multiplication in computer arithmetic, including the Booth’s algorithm, the array multiplier, and the Wallace tree multiplier.

Overall, computer arithmetic is a complex and important field that underlies many aspects of modern computing. It involves a wide range of concepts and operations, from basic addition and subtraction to advanced algorithms for multiplication and division.


Previous Article
Next Article

Similar Reads

Computer Arithmetic | Set - 1
Negative Number Representation Sign Magnitude Sign magnitude is a very simple representation of negative numbers. In sign magnitude the first bit is dedicated to represent the sign and hence it is called sign bit. Sign bit ‘1’ represents negative sign. Sign bit ‘0’ represents positive sign. In sign magnitude representation of a n - bit number, the
5 min read
Arithmetic Logic Shift Unit in Computer Architecture
Arithmetic Logic Shift Unit (ALSU) is a member of the Arithmetic Logic Unit (ALU) in a computer system. It is a digital circuit that performs logical, arithmetic, and shift operations. Rather than having individual registers calculating the micro operations directly, the computer deploys a number of storage registers which is connected to a common
2 min read
Computer Organization | Basic Computer Instructions
Introduction : Computer organization refers to the way in which the components of a computer system are organized and interconnected to perform specific tasks. One of the most fundamental aspects of computer organization is the set of basic computer instructions that the system can execute. Basic computer instructions are the elementary operations
6 min read
Differences between Computer Architecture and Computer Organization
Computer Architecture is a functional description of requirements and design implementation for the various parts of a computer. It deals with the functional behavior of computer systems. It comes before the computer organization while designing a computer. Computer architecture and computer organization are related but distinct concepts in the fie
3 min read
Performance of Computer in Computer Organization
In computer organization, performance refers to the speed and efficiency at which a computer system can execute tasks and process data. A high-performing computer system is one that can perform tasks quickly and efficiently while minimizing the amount of time and resources required to complete these tasks. There are several factors that can impact
5 min read
Arithmetic instructions in 8085 microprocessor
Arithmetic Instructions are the instructions which perform basic arithmetic operations such as addition, subtraction and a few more. In 8085 microprocessor, the destination operand is generally the accumulator. Following is the table showing the list of arithmetic instructions: OpcodeOperandExplanationExampleADDRA = A + RADD BADDMA = A + McADD 2050
4 min read
Arithmetic instructions in 8086 microprocessor
Arithmetic Instructions are the instructions which perform basic arithmetic operations such as addition, subtraction and a few more. Unlike in 8085 microprocessor, in 8086 microprocessor the destination operand need not be the accumulator. Following is the table showing the list of arithmetic instructions: OPCODE OPERAND EXPLANATION EXAMPLE ADD D,
2 min read
Overflow in Arithmetic Addition in Binary Number System
In Computer Architecture 2's Complement format is widely used. The discussion of overflow here mainly will be with respect to 2's Complement representation for signed Integer. N-bit 2's Complement representation for signed Integer can represent numbers from [Tex]- 2^{n-1} [/Tex]to [Tex]2^{n-1} -1 [/Tex]4 Bit can represent numbers from ( -8 to 7 ) 5
3 min read
Arithmetic Pipeline and Instruction Pipeline
1. Arithmetic Pipeline : An arithmetic pipeline divides an arithmetic problem into various sub problems for execution in various pipeline segments. It is used for floating point operations, multiplication and various other computations. The process or flowchart arithmetic pipeline for floating point addition is shown in the diagram. Floating point
3 min read
Arithmetic Micro-operations in Registers
We can perform arithmetic operations on the numeric data which is stored inside the registers. Example : R3 <- R1 + R2 The value in register R1 is added to the value in the register R2 and then the sum is transferred into register R3. Similarly, other arithmetic micro-operations are performed on the registers. Addition - In addition micro-operat
3 min read