INEL 4215: Computer Architecture and Organization Number Systems Signed numbers.

Slides:



Advertisements
Similar presentations
Computer Engineering (Logic Circuits) Dr. Tamer Samy Gaafar Lec. # 2
Advertisements

COE 202: Digital Logic Design Signed Numbers
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
Signed Numbers.
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
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.
Quiz 1.1 Convert the following unsigned binary numbers to their decimal equivalent: Number2 Number
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Two’s Complement 1.As an action: (Assume the starting value is 1011) 1.Flip the bits from the starting value => Add one to get the answer.
Review Binary Basic Conversion Binary Decimal
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.
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
Number Systems Computer Science 210 Computer Organization.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
3. Representing Integer Data
Binary Representation and Computer Arithmetic
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Lecture 5.
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
Representing Integer Data Book : Chapter ( Subject has no point !! ) A99ACF.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Computer Architecture
Ch.3 - Computer Organization BIT Presentation 5.
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 29, 2004 Lecture Number: 26.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
9.4 FLOATING-POINT REPRESENTATION
1 COMS 161 Introduction to Computing Title: Numeric Processing Date: October 20, 2004 Lecture Number: 23.
Calculating Two’s Complement. The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of.
Representation of Data Ma King Man. Reference Text Book: Volume 2 Notes: Chapter 19.
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.
Operations on Bits Arithmetic Operations Logic Operations
Number Systems and Logic Prepared by Dr P Marais (Modified by D Burford)
Introduction to Number System
By Jariya Phongsai A two's-complement system is a system in which negative numbers are represented by the two's complement of the absolute value; this.
Computer Organization and Design Information Encoding II Montek Singh Wed, Aug 29, 2012 Lecture 3.
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.
Computers and Numbers. Types of Numbers Computers store two different types of numbers: Whole Numbers AKA Integers (mathematics) AKA Fixed Point Numbers.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
IT1004: Data Representation and Organization Negative number representation.
1 COMS 161 Introduction to Computing Title: Computing Basics Date: September 8, 2004 Lecture Number: 7.
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
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.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition.
ECE 3110: Introduction to Digital Systems Number Systems: signed numbers.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Representing Positive and Negative Numbers
Floating Point Numbers Dr. Mohsen NASRI College of Computer and Information Sciences, Majmaah University, Al Majmaah
Signed binary numbers & Binary Codes
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
ECE 2110: Introduction to Digital Systems
ECE 3110: Introduction to Digital Systems
COMS 161 Introduction to Computing
Presentation transcript:

INEL 4215: Computer Architecture and Organization Number Systems Signed numbers

Signed Integer Representation We will not talk about fractional number representation ( ) or floating point representation (i.e x ). 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. –One’s-Complement –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 = = = = = = 7F = = FF = = = = For 8 bits, can represent the signed integers -127 to 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! = = 8A 16 = -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=d n-1 d n-2 …d 1 d 0 One’s Complement Two’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 = Now complement each bit: = FA 16 FA 16 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 = = FA = = = = 7F = = = = = = FF 16 For 8 bits, can represent the signed integers -127 to 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! = FA = FF 16 = -0 !!! Unfortunately, K + 0 = K only works if we use +0, does not work if we use (+0) = = = 5 (ok) 5 + (-0) = FF 16 = = 4 !!! (wrong)

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 = Now complement each bit: = FA 16 Now add one: FA = FB 16 FB 16 is the 8-bit, twos complement representation of -5. NOTE: positive numbers in 2s complement are simply their binary representation.

Twos Complement Examples -5 = = FB = = = = 7F = = = = (note the extended range!) + 0 = = = = (only 1 zero!!!) For 8 bits, can represent the signed integers -128 to 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) = = FB = = 0 !!! Normal binary addition is used for adding numbers that represent twos complement integers.

Sign Extended 2’s Complement What happens if we need to represent the number in with more bits? Lets say 10 bits. What is -5 in Twos Complement, 8 bits? The magnitude 5 in 10-bits is = Now complement each bit: = 3FA 16 Now add one: 3FA = 3FB 16 3FB 16 is the 10-bit, twos complement representation of -5. NOTE: The 8 bit representation of -5 is The 10 bit representation of -5 is

Sign Extended 2’s Complement 12-bit representation of the same numbers -5 = = FFB = = = = 07F = = F = = F = = = =

Compare 12 bits vs. 8 bits -5 = = = = = = = = = = = = = = bits 8 bits

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 To use more bits, extend the sign