# Practical Application for Computer Architecture: Computer Arithmetic

Instructor: Martin Gibbs

Martin has 16 years experience in Human Resources Information Systems and has a PhD in Information Technology Management. He is an adjunct professor of computer science and computer programming.

In this lesson, you will apply your knowledge of binary numbers and perform arithmetic on binary numbers. You will perform operations on both integer and floating point binary numbers.

## Lesson Overview & Knowledge Required

In order to successfully complete this lesson, you should have a solid understanding of binary numbers and how they are represented (both integer and floating-point). After this lesson, you should be able to add binary numbers, and explain how arithmetic operations are carried out on floating-point binary numbers as well.

## Computer Arithmetic

In this section, we will be solving arithmetic problems with binary numbers. We will add, subtract, divide, and multiply binary numbers.

Recall the rules for binary addition:

• 0 + 0 = 0
• 1 + 0 and 0 + 1 = 1
• 1 + 1 = 10
• 1 + 1 + 1 = 11

When adding numbers, you move from right to left. Therefore, the addition of the numbers 11001 and 10001, result in the solution shown in Figure 1 (notice that you carry the 1 up to the top line!):

The final value is 101010 (42).

### Subtraction

The subtraction rules for binary numbers are:

• 1 - 1 = 0
• 1 - 0 = 1
• 10 - 1 = 1

If you have 0 - 1, you have to borrow the 1 from the next place value. Let's subtract 1101 from 10000. Figure 2 shows the result:

### Multiplication

Multiplication of binary numbers is done much similar to multiplying base-10 numbers. You go through the traditional long-multiplication process; however, when you are ready to add the products, the same rules for binary addition follow. Let's look at the multiplication of 12 (1100) by 8 (1000) as shown in Figure 3:

The result is 110000 (96)

### Division

Let's divide 6 by 3. In binary, 6 is 110 , 3 is 11. Figure 4 shows the solution of this division:

### Floating Point Arithmetic

Floating-point representation in binary can be a little tricky. There are variances in how the numbers work in regards to single or double precision. In single precision, there is a bit for the sign, 8 bits for the exponent and 23 for the mantissa. Consider the following:

• 2 x 102

This is a positive value, so the first bit will be a 0 (a negative sign is denoted by a 1). The exponent is 2 and the mantissa is also 2 (10 to the second power).

In a computer, a floating-point binary number needs to be normalized before you can store it. This means that there is only one number for the exponent. Therefore, the number 25.25 becomes:

• 2.525 * 101

There are two options to show this in binary. One displays the decimal, so the value is 11001.01. Recall that single precision splits the sign, exponent, and mantissa into separate blocks of bits. We'll look at single precision. Thus, our number is as follows (we separated the bits for easier reading):

Sign Exponent Mantissa
0 1000 0011 100 1010 0000 0000 0000 0000

When it comes to adding, things can get complicated. If we were to add other decimals, we need to first shift smaller numbers down so the decimal points align AND we have the same exponent. We need to convert 2.25 to .0225 * 101 so that it matches up with 2.525 * 101:

Decimal Normalized Binary
25.25 2.525 * 101 0 1000 0011 100 1010 0000 0000 0000 0000
2.25 0.0225 * 101 0 1000 0110 000 0010 0100 0000 0000 0000

Next, you add by adding the mantissas together as shown below. Remember that 1 + 1 = 10 and so you carry the 1!

To unlock this lesson you must be a Study.com Member.

### Register for a free trial

Are you a student or a teacher?

#### See for yourself why 30 million people use Study.com

##### Become a Study.com member and start learning now.
Back
What teachers are saying about Study.com

### Earning College Credit

Did you know… We have over 160 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.