ECE 2110: Introduction to Digital Systems

Slides:



Advertisements
Similar presentations
COE 202: Digital Logic Design Signed Numbers
Advertisements

CS 151 Digital Systems Design Lecture 3 More Number Systems.
Signed Numbers.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
1 Module 2: Floating-Point Representation. 2 Floating Point Numbers ■ Significant x base exponent ■ Example:
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
Binary numbers and arithmetic. ADDITION Addition (decimal)
The Binary Number System
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Computer Architecture
Complement Numbers. Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude.
9.4 FLOATING-POINT REPRESENTATION
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Number Systems and Logic Prepared by Dr P Marais (Modified by D Burford)
INEL 4215: Computer Architecture and Organization Number Systems Signed numbers.
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
CEC 220 Digital Circuit Design Binary Codes
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
IT1004: Data Representation and Organization Negative number representation.
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
ECE 3110: Introduction to Digital Systems Number Systems: signed numbers.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
Fixed-point and floating-point numbers Ellen Spertus MCS 111 October 4, 2001.
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Representing Positive and Negative Numbers
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Floating Point Numbers Dr. Mohsen NASRI College of Computer and Information Sciences, Majmaah University, Al Majmaah
MATH Lesson 2 Binary arithmetic.
CHAPTER 5: Representing Numerical Data
CS2100 Computer Organisation
Department of Computer Science Georgia State University
Cosc 2150: Computer Organization
Signed binary numbers & Binary Codes
Computer Architecture & Operations I
Addition and Subtraction
CHAPTER 9 COMPUTER ARITHMETIC - ALU
Negative Binary Numbers
Introduction To Computer Science
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
Computer Science 210 Computer Organization
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Negative Binary Numbers
CSE 102 Introduction to Computer Engineering
CHAPTER 4: Representing Integer Data
Overview Introduction Data representation Fixed Point Representation
CS1010 Programming Methodology
Data Structures Mohammed Thajeel To the second year students
Computer Science 210 Computer Organization
Data Representation Data Types Complements Fixed Point Representation
Data Representation in Computer Systems
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Digital Logic & Design Lecture 02.
ECEG-3202 Computer Architecture and Organization
Data Representation – Chapter 3
EEL 3705 / 3705L Digital Logic Design
ECE 3110: Introduction to Digital Systems
COMS 161 Introduction to Computing
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
Lecture No.5.
COMS 361 Computer Organization
Chapter 1 Introduction.
Today Binary addition Representing negative numbers 2.
Presentation transcript:

ECE 2110: Introduction to Digital Systems Number Systems: signed numbers

Previous class Summary Unsigned addition/subtraction

Signed Integer Representation We have been ignoring large sets of numbers so far; ie. the sets of signed integers, fractional numbers, and floating point numbers. We will not talk about fractional number representation (10.3456) or floating point representation (i.e. 9.23 x 1013). We WILL talk about signed integer representation. The PROBLEM with signed integers ( - 45, + 27, -99) is the SIGN! How do we encode the sign? The sign is an extra piece of information that has to be encoded in addition to the magnitude. Hmmmmm, what can we do??

Representation of Negative Numbers Signed-Magnitude Representation: Negates a number by changing its sign. Complement Number Systems: negates a number by taking its complement. Diminished Radix-Complement Representation One’s-Complement Radix-Complement Representation Two’s-Complement

Signed Magnitude Representation Signed Magnitude (SM) is a method for encoding signed integers. The Most Significant Bit is used to represent the sign. ‘1’ is used for a ‘-’ (negative sign), a ‘0’ for a ‘+’ (positive sign). The format of a SM number in 8 bits is: smmmmmmm where ‘s’ is the sign bit and the other 7 bits represent the magnitude. NOTE: for positive numbers, the result is the same as the unsigned binary representation.

Signed Magnitude Examples (8 bits) -5 = 1 00001012 = 8516 +5 = 0 00001012 = 0516 +127 = 0 11111112 = 7F16 -127 = 1 11111112 = FF16 + 0 = 0 00000002 = 0016 - 0 = 1 00000002 = 8016 For 8 bits, can represent the signed integers -127 to +127. For N bits, can represent the signed integers -(2(N-1) - 1) to + (2(N-1) - 1)

Signed Magnitude comments Signed magnitude easy to understand and encode. Is used today in some applications. One problem is that it has two ways of representing 0 (-0, and +0) . Mathematically speaking, no such thing as two representations for zeros. Another problem is that addition of K + (-K) does not give Zero! -5 + 5 = 8516 + 0516 = 8A16 = -10 !!! Have to consider the sign when doing arithmetic for signed magnitude representation.

Complement Number Systems Two numbers in a complement number system can be added/subtracted directly without the sign and magnitude checks. Fixed number of digits, n D=dn-1dn-2…d1d0 Diminished Radix-Complement Radix-Complement

Diminished Radix-Complement Given an n-digit number D; Complement is obtained by subtracting D from rn-1 <----complementing each individual digit. Decimal (r=10): 9’s complement Binary (r=2): one’s complement

One’s Complement Representation To encode a negative number, get the binary representation of its magnitude, then COMPLEMENT each bit. Complementing each bit mean that 1s are replaced with 0s, 0s are replaced with 1s. What is -5 in Ones Complement, 8 bits? The magnitude 5 in 8-bits is 000001012 = 0516 Now complement each bit: 111110102 = FA16 FA16 is the 8-bit, ones complement number of -5. NOTE: positive numbers in 1s complement are simply their binary representation.

One’s Complement Examples -5 = 111110102 = FA16 +5 = 000001012 = 0516 +127 = 011111112 = 7F16 -127 = 100000002 = 8016 + 0 = 000000002 = 0016 - 0 = 111111112 = FF16 For 8 bits, can represent the signed integers -127 to +127. For N bits, can represent the signed integers -(2(N-1) - 1) to + (2(N-1) - 1)

One’s Complement Comments Still have the problem that there are two ways of representing 0 (-0, and +0) . Mathematically speaking, no such thing as two representations for zeros. However, addition of K + (-K) now gives Zero! -5 + 5 = FA16 + 0516 = FF16 = -0 !!! Unfortunately, K + 0 = K only works if we use +0, does not work if we use -0. 5 + (+0) = 0516 + 0016 = 0516 = 5 (ok) 5 + (-0) = 0516 + FF16 = 0416 = 4 !!! (wrong)

Radix-Complement Given an n-digit number D; Complement is obtained by subtracting D from rn <----complementing each individual digit and adding 1. Decimal (r=10): 10’s complement Binary (r=2): two’s complement

Two’s Complement Representation To encode a negative number, get the binary representation of its magnitude, COMPLEMENT each bit, then ADD 1. (get Ones complement, then add 1). What is -5 in Twos Complement, 8 bits? The magnitude 5 in 8-bits is 000001012 = 0516 Now complement each bit: 111110102 = FA16 Now add one: FA16 + 1 = FB16 FB16 is the 8-bit, twos complement representation of -5. NOTE: positive numbers in 2s complement are simply their binary representation.

Twos Complement Examples -5 = 111110112 = FB16 +5 = 000001012 = 0516 +127 = 011111112 = 7F16 -127 = 100000012 = 8116 -128 = 100000002 = 8016 (note the extended range!) + 0 = 000000002 = 0016 - 0 = 000000002 = 0016 (only 1 zero!!!) For 8 bits, can represent the signed integers -128 to +127. For N bits, can represent the signed integers -2(N-1) to +(2(N-1) - 1) Note that negative range extends one more than positive range.

Twos Complement Comments Twos complement is the method of choice for representing signed integers. It has none of the drawbacks of Signed Magnitude or Ones Complement. There is only one zero, and K + (-K) = 0. -5 + 5 = FB16 + 0516 = 0016 = 0 !!! Normal binary addition is used for adding numbers that represent twos complement integers.

Summary Signed-magnitude, two’s complement, one’s complement Different for negatives numbers Representations of positive numbers are SAME. 0 may have different representations. Sign bit: 0 for positive, 1 for negative

Next… Signed numbers conversions Signed addition/Subtraction Reading 2.6--2.7