In computers, addition is performed by the Arithmetic Logic Unit (ALU). The two numbers you add together will be stored in two separate registers. The ALU will add these two numbers and store the result in another record. Depending on the size of the registers, this addition can be performed on 8-bit, 16-bit, 32 bit or 64-bit numbers. This blog post will discuss how the acquisition is performed in different sizes of registers.
8-bit addition:
When you add two 8-bit numbers, the result will be stored in another register. The ALU will first load A’s value into its first input port and load B into its second input port. It then performs the + operation and stores the result in a predetermined register (Register 2). The total number of steps required to solve this additional problem is 3.
16-bit addition:
When you add two 16-bit numbers, the result can be either a 32 bit or 16-bit. In our previous example of an 8-bit addition, we knew that the result would be stored only in one register (Register 2). In this case, the result can be stored in register 2 or Register 1. In the case of 32-bit numbers, the result can be calculated using either addition or subtraction, depending on the operands. The algorithm to add 16-bit numbers is as follows:
Let A = 16 bit number and B = 16 bit number
P 1 = A XOR B
P 2= A + B
P1 and P2 temporaries are being formed for different values of A and B:
After P1 and P2 are computed, you will have to add them to get the final result. This can be done using an adder.
64-bit addition:
When you add two 64-bit numbers, the result can be a 128-bit number or an upper 32-bit number. For example, the algorithm to add 64-bit numbers is as follows:
Let A = 64bit number and B = 64bit number
P 1 = A XOR B
P 2= A + B
The following table shows how P1 and P2 temporaries are being formed for different values of A and B: After P1 and P2 are computed, you will have to add them to get the final result. This can be done using an adder.
Some of the exciting aspects of addition with 64 bits are:
First, it calculates the XOR of the two numbers to compute P1 and P2. This is achieved by using a large number (8 bits) since one can know that A will not be greater than B. It also uses this time-honoured trick of keeping track of the number of zeroes that precede and follow a number to compute the result without going through all possible combinations (all 2**64 outcomes). Second, there is no carry bit, so intermediate results don’t overflow values in 64-bit registers. Last, the final addition can be done with a 64-bit adder or two 32-bit additions.
Binary Addition: Next, we will discuss the binary addition of integers. Binary addition is performed by adding two numbers and storing the result in a register. The algorithm for binary addition is as follows:
Let A = [0] and B = [1].
Then, A+B can be expressed as:
A+B = B<<1|B>>8|B>>>7|B>>>4 (6 steps). Note that if the second bit of B is 0, then the result would not be affected. The operation A+B>>1 and A+B*2 both lead to the same result (i.e., B<<1 and B>>2).
There are many applications of binary addition
One of the most commonly used applications is in audio and video encoding. For example, converting analog signals to digital is called sampling. The sampling rate or frequency is given by the number of bits per second (bps) used to represent a given audio bandwidth. For example, CD uses a sampling rate of 44100 BPS, which means it will take 44100 samples per second for an 8 kHz bandwidth.
Arithmetic Operations-Addition is daily in computers, and almost every algorithm can be expressed in some form of an arithmetic expression. For example, if we want to find the average of a set of numbers, we could use the following formula:
Initialization: C = 0; A = [0] and B = [1].
Conclusion
Addition and subtraction are fundamental Arithmetic Operations-Addition. In computer graphics, addition and subtraction are combined in texture mapping. These operations are also used in many other algorithms such as connectivity, sorting, etc.
Addition and subtraction are mathematical operations. This means we can write an algorithm that does these operations on many different number types.