Computer Arithmetic. Appendix A Fall 2003 Lec.03-58

Similar documents
Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

Number System. Introduction. Decimal Numbers

Number representations

CHW 261: Logic Design

Divide: Paper & Pencil

Korea University of Technology and Education

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

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

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

Module 2: Computer Arithmetic

COMP Overview of Tutorial #2

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

COE 202- Digital Logic. Number Systems II. Dr. Abdulaziz Y. Barnawi COE Department KFUPM. January 23, Abdulaziz Barnawi. COE 202 Logic Design

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

in this web service Cambridge University Press

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

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

COMPUTER ARITHMETIC (Part 1)

Numbering systems. Dr Abu Arqoub

Number Systems. Both numbers are positive

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

Chapter 5 : Computer Arithmetic

Chapter 1 Emad Felemban

EE292: Fundamentals of ECE

1DT157 Digitalteknik och datorarkitekt. Digital technology and computer architecture, 5p

Chapter 1 Review of Number Systems

CPS 104 Computer Organization and Programming

Number Systems CHAPTER Positional Number Systems

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

Introduction to Computer Science-103. Midterm

T02 Tutorial Slides for Week 2

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

Chapter 2 Data Representations

Chapter 3: Arithmetic for Computers

D I G I T A L C I R C U I T S E E

Chapter 10 Binary Arithmetics

World Inside a Computer is Binary

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Level ISA3: Information Representation

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

MC1601 Computer Organization

MACHINE LEVEL REPRESENTATION OF DATA

(+A) + ( B) + (A B) (B A) + (A B) ( A) + (+ B) (A B) + (B A) + (A B) (+ A) (+ B) + (A - B) (B A) + (A B) ( A) ( B) (A B) + (B A) + (A B)

Organisasi Sistem Komputer

Digital Fundamentals

Data Representations & Arithmetic Operations

Number Systems and Computer Arithmetic

Lecture 8: Addition, Multiplication & Division

Introduction to Computers and Programming. Numeric Values

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

EE 486 Winter The role of arithmetic. EE 486 : lecture 1, the integers. SIA Roadmap - 2. SIA Roadmap - 1

Number Systems. TA: Mamun. References: Lecture notes of Introduction to Information Technologies (ITEC 1011) by Dr Scott MacKenzie

Lecture 2: Number Systems

CS & IT Conversions. Magnitude 10,000 1,

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

Chapter 2 Binary Values and Number Systems

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

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

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

CMPE223/CMSE222 Digital Logic Design. Positional representation

MIPS Integer ALU Requirements

Chapter 4. Operations on Data

EECS150 - Digital Design Lecture 13 - Combinational Logic & Arithmetic Circuits Part 3

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS

Internal Data Representation

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

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

Math in MIPS. Subtracting a binary number from another binary number also bears an uncanny resemblance to the way it s done in decimal.

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Logic Design: Part 2

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

Number Systems & Encoding

CS321. Introduction to Numerical Methods

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

UNIT-III COMPUTER ARTHIMETIC

CPE300: Digital System Architecture and Design

COPYRIGHTED MATERIAL. Number Systems. 1.1 Analogue Versus Digital

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Introduction to Numbering Systems

Chapter 5: Computer Arithmetic

Electronic Data and Instructions

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

COMPUTER ORGANIZATION AND. Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers

Chapter 4 Section 2 Operations on Decimals

Microcomputers. Outline. Number Systems and Digital Logic Review

Chapter 2: Number Systems

CO212 Lecture 10: Arithmetic & Logical Unit

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

Digital Systems and Binary Numbers

Chapter 3 Data Representation

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

Arithmetic Logic Unit

Fundamentals of Programming (C)

9 Multiplication and Division

Fixed-Point Math and Other Optimizations

Chapter 10 - Computer Arithmetic

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

EXAMPLE 1. Change each of the following fractions into decimals.

Transcription:

Computer Arithmetic Appendix A 18-347 Fall 2003 Lec.03-58

Intro Computer Arithmetic Computers use the binary system Easy to implement in electronics: 1 is 1V, 0 is 0V Easy to implement with switches (transistors!) In theory could do other number systems (egbase 10 with 10 voltage levels but would be unmanageable) for LOGIC and ARITHMETIC: Binary numbers and arithmetic All calculations use binary numbers Integers (positive and negative) Fixed and floating point numbers Boolean Logic Algebra Logic functions between TRUE or FALSE values AND, OR, NOT, EXCLUSIVE OR, NOT-AND. Boolean Algebra deals with LOGIC What makes computer arithmetic interesting however is that it is done in a limited (fixed) number of binary digits (8, 16, 32, 64) 18-347 Fall 2003 Lec.03-59

Radix Number Systems (1) The general form of a decimal number. 18-347 Fall 2003 Lec.03-60

Radix Number Systems (2) The number 2001 in binary, octal, and hexadecimal. 18-347 Fall 2003 Lec.03-61

Radix Number Systems (3) (K) β = (K ν-1 K ν-2 K i K 0. K -1 K -2 K -μ ) β K ν-1 : Mostsignificantbit(MSB) K -μ : Leastsignificantbit(LSB) K ν-1 K ν-2 K i K 0 :Integer part K -1 K -2 K -μ :fractional part 18-347 Fall 2003 Lec.03-62

Conversion from One Radix to Another(1) Decimal numbers and their binary, octal, and hexadecimal equivalents. 18-347 Fall 2003 Lec.03-63

Conversion from One Radix to Another(2) Decimal numbers and their binary, octal, and hexadecimal equivalents. 18-347 Fall 2003 Lec.03-64

Conversion from One Radix to Another(3) Examples of octal-to-binary and hexadecimal-to-binary conversion. 18-347 Fall 2003 Lec.03-65

Conversion from One Radix to Another(4) Examples of octal-to-binary and hexadecimal-to-binary conversion. 18-347 Fall 2003 Lec.03-66

Conversion from One Radix to Another(5) Conversion of the decimal number 1492 to binary by successive halving, starting at the top and working downward. For example, 93 divided by 2 yields a quotient of 46 and a remainder of 1, written on the line below 18-347 Fall 2003 Lec.03-67

Conversion from One Radix to Another(6) Conversion of the binary number 101110110111 to decimal by successive doubling, starting at the bottom. Each line is formed by doubling the one below it and adding the corresponding bit. For example, 749 is twice 374 plus the 1 bit on the same line as 749. 18-347 Fall 2003 Lec.03-68

Why this works? Given a number in base 10 (Β) 10 what is its represnetation (A) β in baseβ? Assume(Β) 10 isaninteger: (Β) 10 =(A) β =(A ν-1 A ν-2 Α 0 ) β (Β) 10 =(A) β =A ν-1 xβ ν-1 +A ν-2 xβ ν-2 +.+A 1 xβ 1 +A 0 Ifwedivide(Β) 10 byβthen: ((Β) 10 /β)= (A ν-1 xβ ν-2 +A ν-2 xβ ν-3 +.+A 1 )+(A 0 /β) ((Β) 10 /β)=int((β)10/β)+fraction((β) 10 /β) whereint:istheintegerpartof((β) 10 /β). FRACTION:isthefraction((Β) 10 /β). 18-347 Fall 2003 Lec.03-69

Why this works (A 0 =REM((Β) 10 /β) WhereREM:remainder(Β) 10 /β IfwerepeatthesamestartingnowwithINT((Β) 10 /β)thenthe nextremainderis A 1 andthenextintegerpartis A ν-1 xβ ν-3 +A ν-2 xβ ν-4 +.+A 2 Repeating the same until there is no integer part gives all the digitsof(a) β 18-347 Fall 2003 Lec.03-70

Basic Binary Arithmetic (1) Binary Addition Binary Multiplication 0+0=0 0x0=0 0+1=1 0x1=0 1+0=1 1x0=0 1+1=10 1x1=1 Addition of two POSITIVE integers Α=(10111010) 2 =(186) 10 and Β=(110111) 2 =(55) 10 11111 (carry) 10111010 110111 11110001 =(241) 10 18-347 Fall 2003 Lec.03-71

Basic Arithmetic(2) 101100 multiplicand 1011 multiplier 101100 101100 Partial products 000000 101100 111100100 product (101100) 2 x(1011) 2 =44x11=484=(111100100) 2 18-347 Fall 2003 Lec.03-72

Basic Arithmetic (3) Binary Subtraction 0-0=0 1-0=1 1-1=0 0-1=1 Borrowa1fromthenexthigherposition 0111 (borrow) 10000 101-1011 1010 1=1001 110010 101=101101 1101 100101=-11000 18-347 Fall 2003 Lec.03-73

Basic Arithmetic(4) BinaryDivision (100101) 2 /(101) 2 Dividend 100101 101 Divisor 101 0111 Quotient 1000 101 0111 101 10 Remainder (100101) 2 /(101) 2 =(111) 2 andremainder(10) 2 37/5=7=(111) 2 andremainder2=(10) 2 18-347 Fall 2003 Lec.03-74

Summary: Basic Arithmetic Calculations same as in base-10 system BUT: Addition is very easy and can be implemented extremely fast Multiplication (based on addition) is also straightforward and can be done also very fast Subtraction is messy and slow Division based on subtraction also a big pain Question: how do we represent negative numbers given a limited (fixed) number of digits? 18-347 Fall 2003 Lec.03-75

Representing Negative Numbers Sign bit representations: Signed magnitude One s complement Two s complement In all these the MSB is also the sign bit (0 means positive, 1 means negative) Other representations: Excess 2 m 1 e.g., for 8 bits subtract 128 to get the number 18-347 Fall 2003 Lec.03-76

Signed Magnitude 18-347 Fall 2003 Lec.03-77

Signed Magnitude Trouble is that sign and magnitude must be treated separately Magnitudes MUST BE COMPARED to do the correct operation on them (depending on the signs ) 18-347 Fall 2003 Lec.03-78

One s & Two s complement Idea: represent negative numbers (given a fixed number of digits) with their complements: Α: Integer number n digits (represented in base b) Α c =basebcomplementofα = b n A in decimal 10 s complement in binary Two s complement Α c-1 = baseb-1complementofα= b n A 1 in decimal 9 s complement in binary One s complement 18-347 Fall 2003 Lec.03-79

One s & Two s complement (2) Two scomplement:α c =2 n A e.g.for4bits: complementof0001is2 4 0001=10000 0001=1111 One scomplementα c-1 =(b n 1) A e.g.for4bits: complementof0001is(2 4 1) 0001=1111 0001=1110 18-347 Fall 2003 Lec.03-80

One s & Two s complement (3) One scomplement change1to0and0to1 IF we compute one s complement then two s complement differsby1:add1toone scomplement Alternativewaytocomputetwo scomplement: Start from the rightmost (least significant bit) keep all the 0 s and the first 1. Reverse all the digits to the LEFT of the first 1. 18-347 Fall 2003 Lec.03-81

One s & Two s complement(4) ΑandΒarendigitnumbers:compute C=Β A Β+Α c = B+(b n A)=b n +(B A) IfΒ>Athen B Aisapositivenumber and the above result is C (n digits) but with an additional 1 on the left(i.e., in position n+1) If Α>Bthen: B Aisnegativeandcanbewrittenas (A B) and the equation becomes Β + Α c = b n (Α Β) which is the two s complement representation of the result! 18-347 Fall 2003 Lec.03-82

One s & Two s complement(5) Examples Two s complement additions in 4 bits +3 0011-2 1110 +4 +0100 + -6 +1010 +7 0111-8 1 1000 +6 0110 +4 0100 +-3 +1101 +-7 +1001 +3 1 0011-3 1101 18-347 Fall 2003 Lec.03-83

One s & Two s complement(6) Difference in one s complement and two s complement additions: 18-347 Fall 2003 Lec.03-84

Negative Binary Numbers (1) Negative 8-bit numbers in four systems. 18-347 Fall 2003 Lec.03-85

Negative Binary Numbers (2) Negative 8-bit numbers in four systems. 18-347 Fall 2003 Lec.03-86

Overflow Overflow means that a number cannot be represented In Two s complement addition: If numbers are of opposite signs overflow cannot occur If numbers are of the same sign and the result is of different sign the overflow! Rule: carry in to sign bits!= carry out of sign bits 18-347 Fall 2003 Lec.03-87

Summary Unsignednumbers Signednumbers Signmagnitude One scomplement Two scomplement Excess2 (m-1) Stillonlyintegers Howtorepresentfractionsetc? Useadecimalpoint Fixedpoint Floating point 18-347 Fall 2003 Lec.03-88

Fixed Point Fixedpointnumbers:dddd.dd Aspecificnumberofdigitstorepresent<1 Butstillverysmallrange Usedmostlyinembeddedsystemswhentherangeofnumbers is known 18-347 Fall 2003 Lec.03-89

Floating Point Numbers 18-347 Fall 2003 Lec.03-90

Floating Point Numbers 18-347 Fall 2003 Lec.03-91

Floating Point Numbers 18-347 Fall 2003 Lec.03-92

Floating Point Numbers 18-347 Fall 2003 Lec.03-93

Floating Point Numbers 18-347 Fall 2003 Lec.03-94

Floating Point Numbers 18-347 Fall 2003 Lec.03-95

Floating Point Numbers 18-347 Fall 2003 Lec.03-96

Floating Point Numbers 18-347 Fall 2003 Lec.03-97

Floating Point Numbers 18-347 Fall 2003 Lec.03-98