A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Similar documents
Number System. Introduction. Decimal Numbers

4/8/17. Admin. Assignment 5 BINARY. David Kauchak CS 52 Spring 2017

CS & IT Conversions. Magnitude 10,000 1,

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

Octal and Hexadecimal Integers

COMP Overview of Tutorial #2

World Inside a Computer is Binary

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

Introduction to Computers and Programming. Numeric Values

Numerical Representations On The Computer: Negative And Rational Numbers

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

Number Systems. Both numbers are positive

Number representations

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

Binary Adders: Half Adders and Full Adders

Chapter 3: part 3 Binary Subtraction

Chapter 3: Arithmetic for Computers

Chapter 4. Operations on Data

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Representation of Non Negative Integers

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Computer Organization

Introduction to Computer Science-103. Midterm

Signed Binary Numbers

Numerical Representations On The Computer: Negative And Rational Numbers

Chapter 1 Review of Number Systems

T02 Tutorial Slides for Week 2

CHW 261: Logic Design

Signed umbers. Sign/Magnitude otation

MACHINE LEVEL REPRESENTATION OF DATA

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Lecture 8: Addition, Multiplication & Division

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Number Systems. Readings: , Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs

Chapter 10 Binary Arithmetics

Chapter 2 Bits, Data Types, and Operations

9/23/15. Agenda. Goals of this Lecture. For Your Amusement. Number Systems and Number Representation. The Binary Number System

8/27/2016. ECE 120: Introduction to Computing. Graphical Illustration of Modular Arithmetic. Representations Must be Unambiguous

ECE 30 Introduction to Computer Engineering

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

Module 2: Computer Arithmetic

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Chapter 2 Bits, Data Types, and Operations

CS 64 Week 1 Lecture 1. Kyle Dewey

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

Chapter 2 Bits, Data Types, and Operations

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

CS/EE1012 INTRODUCTION TO COMPUTER ENGINEERING SPRING 2013 HOMEWORK I. Solve all homework and exam problems as shown in class and sample solutions

Chapter 1. Digital Systems and Binary Numbers

Number Systems CHAPTER Positional Number Systems

Computer Architecture and Organization

Chapter 2 Data Representations

COMP 122/L Lecture 2. Kyle Dewey

Chapter 5 : Computer Arithmetic

COMP2611: Computer Organization. Data Representation

BINARY SYSTEM. Binary system is used in digital systems because it is:

Digital Fundamentals. Lab 6 2 s Complement / Digital Calculator

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Chapter 5: Computer Arithmetic. In this chapter you will learn about:

Numbers and Representations

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Data Representations & Arithmetic Operations

Learning Objectives. Binary over Decimal. In this chapter you will learn about:

Chapter 2 Bits, Data Types, and Operations

Advanced Computer Architecture-CS501

The. Binary. Number System

CS 31: Intro to Systems Binary Arithmetic. Kevin Webb Swarthmore College January 26, 2016

UNIT 7A Data Representation: Numbers and Text. Digital Data

Part 2,Number Systems Questions

MC1601 Computer Organization

Inf2C - Computer Systems Lecture 2 Data Representation

Level ISA3: Information Representation

CS 261 Fall Mike Lam, Professor Integer Encodings

Divide: Paper & Pencil

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Organisasi Sistem Komputer

CMPE223/CMSE222 Digital Logic Design. Positional representation

Number Systems (2.1.1)

EE 109 Unit 6 Binary Arithmetic

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

Unified Engineering Fall 2004

COMPUTER ARITHMETIC (Part 1)

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation

Module 1: Information Representation I -- Number Systems

Chapter 2 Bits, Data Types, and Operations

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Chapter 2: Number Systems

MYcsvtu Notes DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah

Chapter Three. Arithmetic

CHAPTER 2 Data Representation in Computer Systems

Chapter 5: Computer Arithmetic

Number Systems and Number Representation

Transcription:

Complement Number Systems A complement number system is used to represent positive and negative integers A complement number system is based on a fixed length representation of numbers Pretend that integers are represented by two decimal digits: (00) 10c through (99) 10c This is a two digit, tens complement number system If (a) 10c + (b) 10c = 100, then the 2-digit, tens complement numbers (a) 10c and (b) 10c are negatives of one another In a 2-digit tens complement system, the overflow carry digit 1 is discarded Complement Number Systems Consider the examples: 1 1 0 Carry 3 4 6 6 1 0 0 1 1 0 Carry 4 9 5 1 1 0 0 1 1 0 Carry 1 9 9 1 0 0 By convention 34, 49, and 1 are all positive and represent their working values And, 66, 51, and 99 represent 34, 49, and 1 4-Bit Twos Complement Number System Consider a 4-bit twos complement number system of numbers That is, integers are represented by four bits: (0000) 2c through (1111) 2c 1

Complement Number Systems You can draw a graph that shows the relationship between complement numbers and their working decimal definitions Here s the graph of the 4-digit tens complement system decimal values 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 A B C D 14 E 15 F 0 1 2 3 4 5 6 7 complement numbers In this example, a working decimal value a is represented by the complement number a where { a if 0 a < 8 a = a + 16 if a < 0 Why Use Complement Number Systems? A complement number system make addition and subtraction easy to implement in hardware In fact, there no subtraction, just addition on integers (positive and negative whole numbers) Using the common signed-magnitude notation, computing a b when a b and when a < b requires different logic A good exercise is to write the logic for computing a b under these two conditions Tens Complement Notation Here are two examples of negatives in the tens complement numbers system 1 Let a = (67) 10c and b = (33) 10c be 2 digit, tens complement numbers Since a + b = 67 + 33 = 100, (67) 10c and (33) 10c are negatives of each other The convention is (33) 10c = 33 and (67) 10c = 33 2 Let a = (048) 10c and b = (952) 10c be 3 digit, tens complement numbers Since a + b = 48 + 952 = 1000, (048) 10c and (952) 10c are negatives of each other The convention is (048) 10c = 48 and (952) 10c = 48 2

Tens Complement Notation Using two digits: (00) 10 through (49) 10c are positive and represent their normal values While, (50) 10c through (99) 10c are negative and represent values 50 through 1 Using three digits: (000) 10 through (499) 10c are positive and have their normal values While, (500) 10c through (999) 10c are negative and have values 500 through 1 Tens Complement Notation The length of tens complement numbers can be padded Positive numbers can be padded with 0 s on the left This is because 34 = (34) 10c = (034) 10c = (0034) 10c = (00034) 10c 34 66 034 966 0034 9966 00034 99966 100 1000 10000 100000 Likewise, negative numbers can be padded with 9 s on the left 21 = (79) 10c = (974) 10c = (9979) 10c = (99979) 10c Twos Complement Notation Twos complement notation is interesting because computers most often store integers in twos complement notation The basic idea is identical to all notations The twos complement numbers (a) 2c and (b) 2c are negatives of one another if they sum to 0 For instance, Carries 1 1 1 1 1 1 0 0 (a) 2c 1 0 0 1 1 1 0 0 (b) 2c 0 1 1 0 0 1 0 0 Sum 1 0 0 0 0 0 0 0 0 In an 8-bit word, the last (ninth) overflow carry bit is discarded 3

Simple Test of Positive and Negative Twos Complement Numbers The most significant (leftmost) bit indicates if a twos complement number is positive or negative Small numbers, those with a leading 0, are positive and represent their normal values Large numbers, those with a leading 1, are negative and represent a negatively shifted value The amount of the negative shift depend on the size of the representation How to Negate a Twos Complement Number Algorithm 1 (Negating a Twos Complement Number) Given a twos complement number (a) 2c 1 Copy (a) 2c s bits from right-to-left up to and including the first 1 2 Flip the remaining bits in (a) 2c Examples of Negating Twos Complement Numbers Consider the examples: 1 The negative of (1001 0000) 2c is (0111 0000) 2c The least significant bits 1 0000 are copied up to and including the first 1 The remaining bits 100 are flipped to get 011 2 The negative of (1001 0100) 2c is (0110 1100) 2c The least significant bits 100 are copied The remaining bits 1001 0 are flipped to get 0110 1 Converting a Twos Complement Number to Decimal Algorithm 2 (Conversion of Twos Complement to Decimal) Let (a) 2c be a twos complement number 1 If (a) 2c is not negative (if the most significant [leftmost] bit is 0) use Horner s rule to convert (a) 2c 2 If (a) 2c is not positive (if the most significant [leftmost] bit is 1) either: (a) use Horner s rule to convert (a) 2c and subtract 2 a from the result, or (b) Negate (a) 2c using the Negation Algorithm, use Horner s rule on the negative, and negate the result 4

Example: Twos Complement Number to Decimal Let a = (0011 1100) 2c be a twos complement number Since a is positive (leftmost bit is 0) Simply use Horner s rule to convert a to decimal Horner s Rule 0 0 1 1 1 1 0 0 0 0 2 6 14 30 60 0 0 1 3 7 15 30 60 Example: Twos Complement Number to Decimal Let a = (1011 1100) 2c be a twos complement number Since a is negative (leftmost bit is 1) Negate a to get a = (0100 0100) 2c Convert a using Horner s rule Horner s Rule 0 1 0 0 0 1 0 0 0 1 2 4 8 18 36 0 1 1 2 4 9 18 36 Therefore, a = (1011 1100) 2c = 36 Converting a Decimal to Twos Complement Algorithm 3 (Conversion of Decimal to Twos Complement) Let (a) 10 be a decimal number 1 If (a) 10 is positive (a) Use repeated remaindering to compute an unsigned binary (b) Append a leftmost 0 to the result 2 If (a) 10 is negative (a) Use repeated remaindering on a to compute an unsigned binary (b) Append a leftmost 0 to the result (c) Use the Negation Algorithm to negate the result 5

Example: Decimal to Twos Complement Notation Let a = +37 be decimal number Notice a = +37 is a signed integer You must account for the + sign in the twos complement representation of a First, use repeated remaindering to convert 37 to an unsigned binary 37 2 (18, 1) 37 = 1 18 2 (9, 0) 37 = 01 9 2 (4, 1) 37 = 101 4 2 (2, 0) 37 = 0101 2 2 (1, 0) 37 = 00101 1 2 (0, 1) 37 = (10 0101) 2 Next, prepend a 0 to represent + +37 = (010 0101) 2c Example: Decimal to Twos Complement Notation Let a = 37 be decimal number Notice a = 37 is a signed integer You must account for the sign in the twos complement representation of a First, as in the previous slide, 37 to an unsigned binary: 37 = (10 0101) 2 Next, prepend a 0 to represent + +37 = (010 0101) 2c Lastly, use the Negation Algorithm do compute: 37 = (101 1011) 2c 6