OperationsonBits

# OperationsonBits - Kingdom Of Saudi Arabia Al-Imam Muhammad...

This preview shows pages 1–11. Sign up to view the full content.

Operations on Bits Chapter 4 in “Foundation of Computer System” Kingdom Of Saudi Arabia Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Information System Department 1 st semester, 2010 – 2011 CS 224: Computer Organization 1 T. Hala A. Al-Rumaih

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Introduction Operation on bits can be divided in to two broad categories: 2
Arithmetic Operations It involves adding, subtracting, multiplying and dividing. All Arithmetic operations (+, -, *, /) can e applied to integers and floating-point number. Arithmetic Operations on integers: We are focusing on addition and subtraction. The multiplication operation can be implemented in software using repeated addition. The Division operation can be implemented in software using repeated subtraction. We will use the two’s complement representation because it is the only method to store integer in computer today. 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Adding in two’s Complement Adding numbers in 2’s complement is like adding the numbers in decimal, you can add column by column and if there is a carry, it is added to the next column. You should remember that you are dealing with binary digits, not decimal digits. When you add 2 bits, the result is 0 or 1 . You have to carry a 1 that is propagated to the next column. 4
Adding in two’s Complement (Cont.) Rule of Adding Integers in two’s Complement: 5 Add 2 bits and propagate the carry to the next column. If there is a final carry after the leftmost column addition, discard it. Number of 1s Result Carry None 0 - One 1 - Two 0 1 Three 1 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Adding in two’s Complement (Cont.) Ex(1): Add two numbers in two’s complement representation using 8 -bit memory location (+17) + (+22) (+39) Solution: +17 00010001 +22 00010110 (+17) + (+22) = 00100111= +39 6
Adding in two’s Complement (Cont.) Ex(2): Add 24 and -17 both numbers in two’s complement representation and using 8-bit memory location (+24) + (-17) (+7) Solution : +24 00011000 -17 “two’s complement rule with the –ve number” -17 00010001 11101111 (+24) + (-17) = 00000111= +7 7

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Adding in two’s Complement (Cont.) Ex(3): Add -35 and 20 both numbers in two’s complement representation and using 8-bit memory location (-35) + (+20) (-15) 8
Adding in two’s Complement (Cont.) Ex(4) : Add +127 and +3 both numbers in two’s complement representation and using 8 -bit memory location (+127) + (+3) (+130) Solution: +127 01111111 +3 00000011 (+127) + (+3) = -126 ? Error We found that the leftmost bit of the result is 1 which means the number is –ve The correct answer should be positive number +130 Overflow 9

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Overflow It is an error occurs when you try to store a number that is not within the range defined by the allocation. When you add numbers in 2’s complement using N bits, make sure that each number and the result are in the range defined for 2’s complement representation.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern