OperationsonBits

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

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
Introduction Operation on bits can be divided in to two broad categories: 2
Image of page 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
Image of page 3

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

View Full Document Right Arrow Icon
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
Image of page 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
Image of page 5

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

View Full Document Right Arrow Icon
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
Image of page 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
Image of page 7

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

View Full Document Right Arrow Icon
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
Image of page 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
Image of page 9

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

View Full Document Right Arrow Icon
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.
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern