Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.

Slides:



Advertisements
Similar presentations
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
Advertisements

COE 202: Digital Logic Design Signed Numbers
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Level ISA3: Information Representation
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 =
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
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.
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.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
CSC 221 Computer Organization and Assembly Language
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Data Representation in Computer Systems
Computer Arithmetic Nizamettin AYDIN
BINARY ARITHMETIC Binary arithmetic is essential in all digital computers and in many other types of digital systems.
Lecture Overview Introduction Positional Numbering System
Data Representation in Computer Systems
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
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.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
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.
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
Operations on Bits Arithmetic Operations Logic Operations
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
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.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Addition and Substraction
1 2.1 Introduction A bit is the most basic unit of information in a computer. –It is a state of “on” or “off” in a digital circuit. –Sometimes these states.
Integers’ Representation. Binary Addition. Two's Complement. Unsigned number representation Binary Addition, Subtraction. Overflow of unsigned numbers.
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
1 CS 151 : Digital Design Chapter 4: Arithmetic Functions and Circuits 4-3 : Binary Subtraction.
Integer Operations Computer Organization and Assembly Language: Module 5.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Nguyen Le CS147.  2.4 Signed Integer Representation  – Signed Magnitude  – Complement Systems  – Unsigned Versus Signed Numbers.
Computer Math CPS120 Introduction to Computer Science Lecture 7.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Dr. ClincyLecture 2 Slide 1 CS Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered.
Lecture 4: Digital Systems & Binary Numbers (4)
Cosc 2150: Computer Organization
Negative Integers Unsigned binary representation can not be used to represent negative numbers. With paper and pencil arithmetic, a number is made negative.
Data Representation in Computer Systems
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
Dr. Clincy Professor of CS
Dr. Clincy Professor of CS
Data Representation in Computer Systems
Data Representation in Computer Systems
Unit 18: Computational Thinking
Dr. Clincy Professor of CS
CPS120: Introduction to Computer Science
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
COMS 361 Computer Organization
Chapter3 Fixed Point Representation
Two’s Complement & Binary Arithmetic
Presentation transcript:

Data Representation in Computer Systems

2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers. To represent negative values, computer systems allocate the high-order bit to indicate the sign of a value. –The high-order bit is the leftmost bit in a byte. It is also called the most significant bit. The remaining bits contain the value of the number.

3 Signed Integer Representation There are three ways in which signed binary numbers may be expressed: –Signed magnitude –One’s complement and –Two’s complement In an 8-bit word, signed magnitude representation places the absolute value of the number in the 7 bits to the right of the sign bit.

4 Signed Magnitude Representation For example, in 8-bit signed magnitude, positive 3 is : Negative 3 is: Computers perform arithmetic operations on signed magnitude numbers in much the same way as humans carry out pencil and paper arithmetic. –Humans often ignore the signs of the operands while performing a calculation, applying the appropriate sign after the calculation is complete.

5 Binary addition is as easy as it gets. You need to know only four rules : = = = = 10 The simplicity of this system makes it possible for digital circuits to carry out arithmetic operations. Let’s see how the addition rules work with signed magnitude numbers... Signed Magnitude Representation

6 Example 1: both positive –Using signed magnitude binary arithmetic, find the sum of 75 and 46. First, convert 75 and 46 to binary, and arrange as a sum, but separate the (positive) sign bits from the magnitude bits. Signed Magnitude Representation

7 Example 1: –Using signed magnitude binary arithmetic, find the sum of 75 and 46. Just as in decimal arithmetic, we find the sum starting with the rightmost bit and work left. Signed Magnitude Representation

8 Example 1: –Using signed magnitude binary arithmetic, find the sum of 75 and 46. In the second bit, we have a carry, so we note it above the third bit. Signed Magnitude Representation

9 Example 1: –Using signed magnitude binary arithmetic, find the sum of 75 and 46. The third and fourth bits also give us carries. Signed Magnitude Representation

10 Example 1: –Using signed magnitude binary arithmetic, find the sum of 75 and 46. Once we have worked our way through all eight bits, we are done. In this example, we were careful careful to pick two values whose sum would fit into seven bits. If that is not the case, we have a problem. Signed Magnitude Representation

11 Example 2: with overflow –Using signed magnitude binary arithmetic, find the sum of 107 and 46. We see that the carry from the seventh bit overflows and is discarded, giving us the erroneous result: = 25 Signed Magnitude Representation

12 The signs in signed magnitude representation work just like the signs in pencil and paper arithmetic. –Example 3: both negative Using signed magnitude binary arithmetic, find the sum of - 46 and Because the signs are the same, all we do is add the numbers and supply the negative sign when we are done. Signed Magnitude Representation

13 Mixed sign addition (or subtraction) is done the same way –Example 4: different sign Using signed magnitude binary arithmetic, find the sum of 46 and The sign of the result gets the sign of the number that is larger. –Note the “borrows” from the second and sixth bits. Signed Magnitude Representation

14 Signed magnitude representation is easy for people to understand, but it requires complicated computer hardware. Another disadvantage of signed magnitude is that it allows two different representations for zero: positive zero and negative zero. For these reasons (among others) computers systems employ complement systems for numeric value representation. Signed Magnitude Representation

15 For example, in 8-bit one’s complement, positive 3 is : Negative 3 is: –In one’s complement, as with signed magnitude, negative values are indicated by a 1 in the high order bit. Complement systems are useful because they eliminate the need for special circuitry for subtraction. –The difference of two values is found by adding the minuend to the complement of the subtrahend. One’s Complement Representation

16 With one’s complement addition, the carry bit is “carried around” and added to the sum. –Example: Using one’s complement binary arithmetic, find the sum of 48 and - 19 We note that 19 in one’s complement is , so -19 in one’s complement is: One’s Complement Representation

17 Although the “end carry around” adds some complexity, one’s complement is simpler to implement than signed magnitude. But it still has the disadvantage of having two different representations for zero: positive zero and negative zero. Two’s complement solves this problem. Two’s complement is the radix complement of the binary numbering system. One’s Complement Representation

18 To express a value in two’s complement: –If the number is positive, just convert it to binary and you’re done. –If the number is negative, find the one’s complement of the number and then add 1. Example: –In 8-bit one’s complement, positive 3 is: –Negative 3 in one’s complement is: –Adding 1 gives us -3 in two’s complement form: Two’s Complement Representation

19 With two’s complement arithmetic, all we do is add our two binary numbers. Just discard any carries emitting from the high order bit. We note that 19 in one’s complement is: , so -19 in one’s complement is: , and -19 in two’s complement is: –Example: Using one’s complement binary arithmetic, find the sum of 48 and One’s Complement Representation

20 When we use any finite number of bits to represent a number, we always run the risk of the result of our calculations becoming too large to be stored in the computer. While we can’t always prevent overflow, we can always detect overflow In complement arithmetic, an overflow condition is easy to detect. Overflow

21 Example: –Using two’s complement binary arithmetic, find the sum of 107 and 46. We see that the nonzero carry from the seventh bit overflows into the sign bit, giving us the erroneous result: = Rule for detecting two’s complement overflow: When the “carry in” and the “carry out” of the sign bit differ, overflow has occurred. Overflow