Representation of Numbers

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

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

Arithmetic Processing

Representation of Non Negative Integers

Number System. Introduction. Decimal Numbers

Numeric Encodings Prof. James L. Frankel Harvard University

World Inside a Computer is Binary

DIGITAL ARITHMETIC. Miloš D. Ercegovac Computer Science Department University of California Los Angeles and

Inf2C - Computer Systems Lecture 2 Data Representation

CS 261 Fall Mike Lam, Professor Integer Encodings

CPE300: Digital System Architecture and Design

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Chapter 3: part 3 Binary Subtraction

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

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

CHW 261: Logic Design

Chapter 2. Data Representation in Computer Systems

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

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

CO212 Lecture 10: Arithmetic & Logical Unit

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

COMP Overview of Tutorial #2

Advanced Computer Architecture-CS501

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

Register Transfer Language and Microoperations (Part 2)

Computer Organization

Chapter 4 Arithmetic Functions

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

SE311: Design of Digital Systems

Principles of Computer Architecture. Chapter 3: Arithmetic

Module 2: Computer Arithmetic

Lecture (02) Operations on numbering systems

Chapter 2 Bits, Data Types, and Operations

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

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

COMPUTER ARITHMETIC (Part 1)

Number representations

Lecture 3: Basic Adders and Counters

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

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

Chapter 2 Bits, Data Types, and Operations

Chapter 2: Number Systems

Signed umbers. Sign/Magnitude otation

Number Systems. Both numbers are positive

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

Integers and Floating Point

Topics. 6.1 Number Systems and Radix Conversion 6.2 Fixed-Point Arithmetic 6.3 Seminumeric Aspects of ALU Design 6.4 Floating-Point Arithmetic

INF2270 Spring Philipp Häfliger. Lecture 4: Signed Binaries and Arithmetic

Korea University of Technology and Education

Lecture 2: Number Systems

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

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

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-2700: Digital Logic Design Winter Notes - Unit 4. hundreds.

Chapter 2 Data Representations

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Floating Point Arithmetic

Chapter 3: Arithmetic for Computers

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

Data Representations & Arithmetic Operations

Chapter 4. Combinational Logic

CS 64 Week 1 Lecture 1. Kyle Dewey

CHAPTER 2 Data Representation in Computer Systems

Chapter 2 Bits, Data Types, and Operations

CHAPTER 2 Data Representation in Computer Systems

Chapter 2 Bits, Data Types, and Operations

Internal Data Representation

CHAPTER 5: Representing Numerical Data

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-278: Digital Logic Design Fall Notes - Unit 4. hundreds.

MACHINE LEVEL REPRESENTATION OF DATA

Organisasi Sistem Komputer

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

Binary Codes. Dr. Mudathir A. Fagiri

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

Digital Fundamentals

Chapter Three. Arithmetic

Chapter 4: Data Representations

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

To design a 4-bit ALU To experimentally check the operation of the ALU

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

Number Systems CHAPTER Positional Number Systems

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS Arithmetic (a) The four possible cases Carry (b) Truth table x y

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

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Course Description: This course includes concepts of instruction set architecture,

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CS356: Discussion #3 Floating-Point Operations. Marco Paolieri

COMP2611: Computer Organization. Data Representation

Chapter 2. Data Representation in Computer Systems

Chapter 10 - Computer Arithmetic

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

Basic Arithmetic (adding and subtracting)

Numbering systems. Dr Abu Arqoub

Divide: Paper & Pencil

CS 101: Computer Programming and Utilization

Chapter 4. Operations on Data

Introduction to Computer Science-103. Midterm

Chapter 1. Digital Systems and Binary Numbers

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

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Transcription:

Computer Architecture 10 Representation of Numbers Made with OpenOffice.org 1

Number encodings Additive systems - historical Positional systems radix - the base of the numbering system, the positive integer that is equivalent to 1 in the next higher counting place fixed radix radix constant, identical for at all positions of digits mixed radix radix vector of bases for all parts of number examples: time (0, 24, 60,60) angle - (0, 360, 60, 60) Digit sets of arbitrary size and composition together with arbitrary radix (negative, fractional, imaginary numbers, etc.) may be suitable in various applications Made with OpenOffice.org 2

Classes of number representation Special codes: BCD, Grey, etc. to meet certain technical requirement / or to avoid physical phenomena Fixed-point codes unsigned NBC, unsigned fractions signed signed-magnitude, biased, 2's-complement signed fractions Redundant number systems Residue Number System Floating-point numbers slash number system (for rational numbers) logarithmic number system exponential number system (IEEE754) Made with OpenOffice.org 3

Basics r radix [0, r-1] standard digit set for r-radix numbering system [0...max] natural number range with n-digits max+1 different number representations max = r n 1 How many positions (digits) are needed to represent natural numbers in arbitrary range [0... max]? n= floor[ log r max ] 1=ceil [log r max 1 ] Made with OpenOffice.org 4

Optimal radix 1. Compact number representation 2. Convenient physical realization 3. Simple arithmetic algorithms What is the best numbering system to represent number in range [0...max]? Optimization criterion for r-radix system: E(r) = r * n (n-digit positions) ln max 1 E r =r n=r log r max 1 =r ln r de dr =ln max 1 ln r 1 ln 2 r =0 r optimal =e=2.71 Optimal radix-3 or radix-2 system (more practical) E 2 E 10 =1.056, E 3 E 2 =1.5 =ln max 1 r ln r Made with OpenOffice.org 5

Unit in the least position (ulp) Fixed-point representation: n-whole digits + l-fractional digits For l=0, number is ordinary integer. n 1 x n 1 x n 2... x 1 x 0 x 1 x 2... x = l i= l x i r i ulp=r l For integer representation (l=0), ulp = 1 Maximal number with n+l fixed-point representation: max=r n 1 r l =r n 1 ulp Made with OpenOffice.org 6

Signed number representations How to represent negative numbers with digits only? (with view of computer application) [ N, +P ]?? [ 0, max ] x?? f, 0 f max -500... 499-2.6... +7.3-1.00... +0.99??? 000... 999 0.0... 9.9 0.00... 2.00 What are the benefits of different representation systems, with special interest in doing machine arithmetic operations? Made with OpenOffice.org 7

Signed-magnitude Converting signed numbers into unsigned form by indicating sign with the leftmost digit Easiest application in binary system: sign = most significant bit Advantages intuitive representation symmetric range simple negation 1110-6 1111-7 0000 +0 0001 +1 0010 +2 Increment 1101-5 1100-4 1011-3 1010-2 1001-1 1000-0 + 0111 +7 0110 +6 0011 +3 0100 +4 0101 +5 Increment Made with OpenOffice.org 8

Signed-magnitude Complex adder hardware: sign detector, magnitude comparator, subtractor circuit or internal complement conversions z = x + y or z = y x or z = x y = (y x) sign x sign y magnitude x magnitude y cmpl x cmpl watch out for two representation of 0 add/sub Control cout cin Adder sign cmpl z cmpl cout sign z magnitude z Made with OpenOffice.org 9

Biased representation Converting signed numbers into unsigned by addition of bias value to all numbers. Other name: excess-bias, e.g. excess-8, excess-128 [ N, +P] [ bias, max bias ] [ 0, max ] bias = N max = N + P = bias + P [ 8, +7 ] [0, 15] [ 0.50, +0.50] [0.00, 1.00] [ 31.5, 7.2] [0, 38.7] Add/Sub arithmetics needs additional operation (+/ bias) addition: x+bias + y + bias = x + y + 2*bias bias subtraction: x+bias (y + bias) = x y + bias negation: (x + bias) = 0+bias (x+bias) = bias x comparison: easy other oper.: difficult Made with OpenOffice.org 10

Biased representation For binary n-bit numbers and bias = 2 n-1, leftmost bit indicate sign 0 negative 1 positive 1110 +6 1111 +7 0000-8 0001-7 0010-6 Increment 1101 +5 1100 +4 1011 +3 1010 +2 1001 +1 + 1000 0 0111-1 0110-2 0011-5 0100-4 0101-3 Increment For binary n-bit numbers and bias = 2 n-1, the weight of leftmost bit is equal to bias value + bias : add 1 to the leftmost bit (complement) bias : sub 1 from the leftmost bit (complement) negation: (x + bias) = bias x = 00...0 x = 11...1+1 x = 11...1 x + 1 = x bit_compl + 1 Made with OpenOffice.org 11

Complement representation Converting signed numbers into unsigned by representing negative values x as the unsigned value M x [ N, +P ] [ 0, N + P ] no overlap of codes M > N + P max. code efficiency M = N + P + ulp M-2 M-1 0 +1 (ulp) [ 4, +11 ] [ 0, 15 ], M = 16 3 = 13 [ 4.00, +3.99] [0.00, 7.99], M = 8.00 2.77 = 5.23 Arithmetic modulo-m: x + y = x + y if x + y P x y = x + (M y) = = x y if x y = M (y x) if y > x y x = y + (M x) = = y x if y x = M (x y) if x > y N M N + +P x y = (M x) + (M y) = = M (x + y) if x+y > N Made with OpenOffice.org 12

Complement representation Arithmetic requirements: negation(m x) : subtraction modulo-m : division/subtraction Selection of M must simplify those operations For r-radix and n-digit fixed-point (symmetrical range) representation: M = r n - radix complement modulo-m: ignoring the carry-out from leftmost position in add-operations negation: each digit-complementation (r 1 digit) and plus ulp to the total M = r n ulp - digit (diminished-radix) complement modulo-m: negation: end-around carry each digit-complementation (r 1 digit) Made with OpenOffice.org 13

2's complement For radix=2 and n-whole digit representation: M=2 n asymmetric range 2 n-1... 2 n-1 ulp x-complement: modulo-m: 2 n x = [(2 n ulp) x] + ulp = 11...1 x + ulp = x bit_ompl + ulp (overflow possible) ignoring the carry-out from leftmost position Increment 1101-3 1100-4 1011-5 1110-2 1010-6 1111-1 1001-7 0000 0 1000-8 0001 1 + 0111 7 0010 2 0110 6 0011 3 0100 4 0101 5 Increment Made with OpenOffice.org 14

2's compl. with fractional digits Binary complement representation (M=2): 1-whole digit & l-fractional digits, e.g. 1.011 range [ 1, +1 ulp] [-1.000, 0.875], ulp=0.125, l=3) 1-whole bit sign Increment 1.101-0.375 1.100-0.500 1.011-0.625 1.111-0.125 1.110-0.250 1.010-0.750 1.001-0.825 0.000 0 1.000-1.000 0.001 0.125 + 0.010 0.250 0.110 0.750 0.111 0.875 0.011 0.375 0.100 0.500 0.101 0.625 Increment Made with OpenOffice.org 15

1's complement For radix=2 and n-digit representation: M=2 n ulp symmetric range 2 n-1 +ulp... 2 n-1 ulp x-complement: (2 n ulp) x = 11...1 x = x bit_ompl (no overflow) modulo-m: ignoring the carry-out from leftmost position and inserting carry to the rightmost position (carry out carry in: end-around carry) double representation of 0: 00...0 and 11...1 no problems in arithmetic modulo-m operations 0 can be left intact (or automatically converted to 0 by hardware) 0 modulo M 0 Made with OpenOffice.org 16

1's complement 1110-1 1111-0 0000 0 0001 1 0010 2 Increment 1101-2 1100-3 1011-4 1010-5 1001-6 1000-7 + 0111 7 0110 6 0011 3 0100 4 0101 5 Increment Made with OpenOffice.org 17

Radix vs digit complement Feature Radix complement Digit complement symmetry no for even radix, yes for even radix, yes for odd radix no for odd radix unique zero yes no complementation x bit_compl + ulp x bit_compl modulo-m addition drop carry-out end-around carry Odd-radix systems have no practical applications Made with OpenOffice.org 18

Efficient complementation in 2's Calculation of -x (x-complement) is slow in 2's complement big disadvantage! However, during subtractions it can be eliminated by simultaneous adding of cin=1, so there is no need for additional arithmetic operation. x y = x + y bit_ompl + ulp x y bit_cmpl add(0)/sub(1) Adder cin cout z Made with OpenOffice.org 19

Extension of 2's & 1's complement n-whole digits & l-fractional digits representation n' & l' representation (n'>n, l'>l) Complementation of positive number is always padding it with 0's, from left and right. Complementation constant M changes from 2 n to 2 n' during conversion (2's complement), thus the difference 2 n' 2 n must be added to old (n&l) representation. 2 n' 2 n contains ones at positions n'-1...n. 2-s complement extension is done by: left: replicating the sign bit (sign extension) right: padding with 0's Complementation constant M changes from 2 n 2 -l to 2 n' 2 -l' during conversion (1's complement), thus the difference 2 n' 2 n + 2 -l' 2 -l must be added to old (n&l) representation. 2 n' 2 n + 2 -l 2 -l' contains ones (1) at positions n'-1...n and positions -(l+1)...-l' 1-s complement extension is done by: left: replicating the sign bit (sign extension) right: replicating the sign bit (sign extension) Made with OpenOffice.org 20

Direct vs indirect sign arithmetic Application of direct or indirect computation approach depends on available algorithms. For some cases, direct algorithms are inefficient, so indirect approach is more universal. Process of sign removal is trivial for all popular signed representations. Sign removal is just one example of preprocessing of arguments. Other examples are: restricting the value to prescribed range (e.g. in trigonometry) detecting restricted values (e.g. in division) scaling the arguments x y x y Signed operation Sign logic Sign removal Unsigned operation Sign correct. f(x,y) f(x,y) Made with OpenOffice.org 21