lec05_Additon_Subtraction

lec05_Additon_Subtraction - Lecture 5 Addition,...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 5 Addition, Subtraction, Logic Operations and ALU Design Computer Architecture CSC 205
Background image of page 1

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

View Full DocumentRight Arrow Icon
Unsigned Binary Integers Unsigned binary numbers are typically used to represent computer addresses or other values that are guaranteed not to be negative. An n-bit unsigned binary integer A = a n-1 a n-2 ... a 1 a 0 has a value of What is 1011 as an unsigned integer? An n-bit unsigned binary integer has a range from 0 to 2 n - 1. What is the value of of the 8-bit unsigned integer 10000001? i i n i a 2 1 0 - =
Background image of page 2
Signed Binary Integers Signed binary numbers are typically used to represent data that is either positive or negative. The most common representation for signed binary integers is the two's complement format. An n-bit 2’s comp binary integer A = a n-1 a n-2 ... a 1 a 0 has a value of What is 1011 as a 2’s comp. integer? An n-bit 2’s comp. binary integer has a range from - 2 n-1 to 2 n-1 - 1. What is the value of the 2’s comp. Integer 10000001? i i n i n n a a 2 2 2 0 1 1 + - = - - -
Background image of page 3

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

View Full DocumentRight Arrow Icon
2’s Comp. Negatation To negate a two's complement integer, invert all the bits and add a one to the least significant bit. What are the two’s complements of 6 = 0110 -4 = 1100 Another way to negate is: Copy all bits to the right of the right-most ‘1’ Copy the right-most ‘1’ Invert all bits to the right-most ‘1’ Which way do you think is more commonly used by hardware? Why?
Background image of page 4
Questions What is the value of the two's complement integer 1111111111111101 in decimal? What is the value of the unsigned integer 1111111111111101 in decimal? What is the negation of the two's complement integer 1010000000000000 in binary?
Background image of page 5

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

View Full DocumentRight Arrow Icon
Two’s Comp. Addition To add two's complement numbers, add the corresponding bits of both numbers with carry between bits. For example, 3 = 0011 -3 = 1101 -3 = 1101 3 = 0011 + 2 = 0010 +-2 = 1110 + 2 = 0010 + -2 = 1110 -------- --------- --------- --------- Unsigned and two’s complement addition are performed exactly the same way, but how they detect overflow differs.
Background image of page 6
Two’s Comp. Subtraction To subtract two's complement numbers we first negate the second number and then add the corresponding bits of both numbers. For example: 3 = 0011 -3 = 1101 -3 = 1101 3 = 0011 - 2 = 0010 - -2 = 1110 - 2 = 0010 - -2 = 1110 ---------- --------- --------- ---------
Background image of page 7

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

View Full DocumentRight Arrow Icon
Overflow When adding or subtracting numbers, the sum or difference can go beyond the range of representable numbers. This is known as overflow. For example, for two's complement numbers, 5 = 0101 -5 = 1011 5 = 0101 -5 = 1011 + 6 = 0110 + -6 = 1010 - -6 = 1010 - +6 = 0110 -------- --------- --------- --------- -5 = 1011 5 = 0101 -5 = 1011 5 = 0101 Overflow creates an incorrect result that should be detected.
Background image of page 8
2’s Comp - Detecting Overflow When adding two's complement numbers, overflow will only occur if the numbers being added have the same sign
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/12/2009 for the course CS 205 taught by Professor H.shaban during the Spring '07 term at Northern Virginia.

Page1 / 34

lec05_Additon_Subtraction - Lecture 5 Addition,...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online