Number Representations

Similar documents
Complement Arithmetic

ECE380 Digital Logic. Positional representation

Conversions between Decimal and Binary

14:332:231 DIGITAL LOGIC DESIGN. Why Binary Number System?

ENGIN 112 Intro to Electrical and Computer Engineering

Worksheets for GCSE Mathematics. Quadratics. mr-mathematics.com Maths Resources for Teachers. Algebra

Lecture 2 Review on Digital Logic (Part 1)

Menu. Review of Number Systems EEL3701 EEL3701. Math. Review of number systems >Binary math >Signed number systems

Chapter 1 CSCI

UNSIGNED BINARY NUMBERS DIGITAL ELECTRONICS SYSTEM DESIGN WHAT ABOUT NEGATIVE NUMBERS? BINARY ADDITION 11/9/2018

EE260: Digital Design, Spring n Digital Computers. n Number Systems. n Representations. n Conversions. n Arithmetic Operations.

14:332:231 DIGITAL LOGIC DESIGN. 2 s-complement Representation

Recurrence Relations

Chapter 4 Number Representations

Logic and Computer Design Fundamentals. Chapter 5 Arithmetic Functions and Circuits

CSE 241 Digital Systems Spring 2013

Total Time = 90 Minutes, Total Marks = 100. Total /10 /25 /20 /10 /15 /20

ECE260: Fundamentals of Computer Engineering

Computer Architecture, IFE CS and T&CS, 4 th sem. Representation of Integer Numbers in Computer Systems

Introduction to Digital Logic Missouri S&T University CPE 2210 Subtractors

Definition: A sequence is a function from a subset of the integers (usually either the set

Lecture 8: Sequential Multipliers

0,..., r 1 = digits in radix r number system, that is 0 d i r 1 where m i n 1

Department of Electrical and Computer Engineering University of Wisconsin - Madison. ECE/CS 352 Digital System Fundamentals.

CS 140 Lecture 14 Standard Combinational Modules

CHAPTER 2 NUMBER SYSTEMS

CpE358/CS381. Switching Theory and Logical Design. Summer

Computer Organization I CRN Test 3/Version 1 CMSC 2833 CRN Spring 2017

Fundamentals of Digital Design

hexadecimal-to-decimal conversion

Computer Architecture 10. Residue Number Systems

Numbering Systems. Contents: Binary & Decimal. Converting From: B D, D B. Arithmetic operation on Binary.

Two Posts to Fill On School Board

1. The graph of a function f is given above. Answer the question: a. Find the value(s) of x where f is not differentiable. Ans: x = 4, x = 3, x = 2,

Chapter 22 : Electric potential

ELCT201: DIGITAL LOGIC DESIGN

P.3 Division of Polynomials

Binary Floating-Point Numbers

LOGIC GATES. Basic Experiment and Design of Electronics. Ho Kyung Kim, Ph.D.

Combinational Logic Design Arithmetic Functions and Circuits

ECE 372 Microcontroller Design

MATH Dr. Halimah Alshehri Dr. Halimah Alshehri

convert a two s complement number back into a recognizable magnitude.

Please read carefully. Good luck & Go Gators!!!

CprE 281: Digital Logic

Elements of Floating-point Arithmetic

Four Important Number Systems

LOWELL WEEKLY JOURNAL. ^Jberxy and (Jmott Oao M d Ccmsparftble. %m >ai ruv GEEAT INDUSTRIES

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Number Representation and Waveform Quantization

L8/9: Arithmetic Structures

KEYWORDS: Multiple Valued Logic (MVL), Residue Number System (RNS), Quinary Logic (Q uin), Quinary Full Adder, QFA, Quinary Half Adder, QHA.

課程名稱 : 數位邏輯設計 P-1/ /6/11

OWELL WEEKLY JOURNAL

Graduate Institute of Electronics Engineering, NTU Basic Division Scheme

Design of Digital Circuits Reading: Binary Numbers. Required Reading for Week February 2017 Spring 2017

Computer Arithmetic. MATH 375 Numerical Analysis. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Computer Arithmetic

Lecture 8. Sequential Multipliers

Elements of Floating-point Arithmetic

Hakim Weatherspoon CS 3410 Computer Science Cornell University

DSP Design Lecture 2. Fredrik Edman.

Chapter 1: Solutions to Exercises

ECE 545 Digital System Design with VHDL Lecture 1. Digital Logic Refresher Part A Combinational Logic Building Blocks

Lecture 11. Advanced Dividers

Combinational Logic. By : Ali Mustafa

Chapter 4. Combinational: Circuits with logic gates whose outputs depend on the present combination of the inputs. elements. Dr.

Worksheets for GCSE Mathematics. Algebraic Expressions. Mr Black 's Maths Resources for Teachers GCSE 1-9. Algebra

Rational Expressions and Functions

Work, Energy, and Power. Chapter 6 of Essential University Physics, Richard Wolfson, 3 rd Edition

Lowell Dam Gone Out. Streets Turned I n t o Rivers. No Cause For Alarm Now However As This Happened 35 Years A&o

Terms of Use. Copyright Embark on the Journey

E40M. Binary Numbers. M. Horowitz, J. Plummer, R. Howe 1

Ex code

Cryptography CS 555. Topic 13: HMACs and Generic Attacks

Residue Number Systems Ivor Page 1

ECE 545 Digital System Design with VHDL Lecture 1A. Digital Logic Refresher Part A Combinational Logic Building Blocks

A A A A A A A A A A A A. a a a a a a a a a a a a a a a. Apples taste amazingly good.

MATH 1080: Calculus of One Variable II Fall 2018 Textbook: Single Variable Calculus: Early Transcendentals, 7e, by James Stewart.

Classical RSA algorithm

SECTION 7: STEADY-STATE ERROR. ESE 499 Feedback Control Systems

Hardware Design I Chap. 4 Representative combinational logic

Redesigning The Element Of Random Access Memory (RAM) For Enhanced Computer Processing Speed

Part 5: Digital Circuits

Digital System Design Combinational Logic. Assoc. Prof. Pradondet Nilagupta

Systems I: Computer Organization and Architecture

Revision : Thermodynamics

Binary Multipliers. Reading: Study Chapter 3. The key trick of multiplication is memorizing a digit-to-digit table Everything else was just adding

Redundant Radix Enumeration Systems

Multiplication of signed-operands

Numbers and Arithmetic

What s the Deal? MULTIPLICATION. Time to multiply

Review for Exam Hyunse Yoon, Ph.D. Assistant Research Scientist IIHR-Hydroscience & Engineering University of Iowa

ENEL Digital Circuit Design. Final Examination

Eureka Lessons for 6th Grade Unit FIVE ~ Equations & Inequalities

We are here. Assembly Language. Processors Arithmetic Logic Units. Finite State Machines. Circuits Gates. Transistors

Uncertain Compression & Graph Coloring. Madhu Sudan Harvard

General Strong Polarization

ELEN Electronique numérique

Math 3336 Section 4.3 Primes and Greatest Common Divisors. Prime Numbers and their Properties Conjectures and Open Problems About Primes

Transcription:

Computer Arithmetic Algorithms Prof. Dae Hyun Kim School of Electrical Engineering and Computer Science Washington State University Number Representations

Information Textbook Israel Koren, Computer Arithmetic Algorithms, Prentice Hall, 1993. 2

Outline Binary number system Radix conversion Negative numbers Signed-magnitude One s complement Two s complement Addition and subtraction Arithmetic shift operations (sign extension) 3

The Binary Number System A binary number of length nn (xx nn 1, xx nn 2,, xx 1, xx 0 ) xx ii : bit ( {0,1}) An nn-digit binary number nn 1 XX = xx nn 1 2 nn 1 + xx nn 2 2 nn 2 + + xx 1 2 1 + xx 0 2 0 = xx ii 2 ii xx ii {0,1} ii=0 radix Example 1011 2 = 1 2 3 + 0 2 2 + 1 2 1 + 1 2 0 = 11 4

The Binary Number System Radix-10 numbers: decimal numbers (101) 10 = 101 Radix-2 numbers: binary numbers (101) 2 = 5 Range of representable numbers [XX mmmmmm, XX mmmmmm ] Example: The range of 4-bit unsigned binary numbers: [0, 15] Overflow An arithmetic operation resulting in a number larger than XX mmmmmm or smaller than XX mmmmmm 5

The Binary Number System The conventional number systems Nonredundant Every number has a unique representation. Weighted nn 1 XX = ii=0 xx ii ww ii ww ii : weight Positional ww ii depends only on the position of the digit xx ii. ww ii = rr ii 0 xx ii rr 1 Otherwise (if xx ii rr), the system becomes redundant. X xx ii xx kk redundant D dd jj 6

The Binary Number System A mixed number (fixed-point representation) (xx kk 1 xx kk 2 xx 1 xx 0. xx 1 xx 2 xx mm ) rr integral part fractional part = (xx kk 1 rr kk 1 + xx kk 2 rr kk 2 + + xx 1 rr 1 + xx 0 rr 0 ) + (xx 1 rr 1 + + xx mm rr mm ) kk 1 = xx ii rr ii ii= mm rr mm : indicates the position of the radix point. ulp: unit in the last position uuuuuu = rr mm 7

Radix Conversion Given XX = XX II + XX FF = kk 1 ii=0 xx ii rr ii + 1 ii= mm xx ii rr ii XX II : integral part XX FF : fractional part rr DD : destination number system Integral part XX II = xx 0 + rr DD (xx 1 + rr DD (xx 2 + + rr DD (xx kk 2 + rr DD xx kk 1 ))) 0 xx ii < rr DD xx 0 = XX II mmmmmm rr DD qq 0 = xx 1 + rr DD xx 2 + rr DD xx 3 + xx 1 = qq 0 mmmmmm rr DD... 8

Radix Conversion Fractional part XX FF = rr DD 1 (xx 1 + rr DD 1 (xx 2 + + rr DD 1 (xx mm 1 + rr DD 1 xx mm ))) 0 xx ii < rr DD xx 1 : the integral part of XX FF rr DD mm 1 = rr DD 1 (xx 2 + + rr DD 1 (xx mm 1 + rr DD 1 xx mm )) xx 2 : the integral part of mm 1 rr DD... Example 46.375 10 = 101110.011 2 9

Negative Numbers: Signed-Magnitude Representation (xx ss xx nn 2 xx nn 3 xx 1 xx 0 ) sign magnitude Positive numbers: 0xxxxx 0xxxxx 2 Negative numbers: (r-1)xxxxx 1xxxxx 2 Range of positive numbers for (ss xx kk 2 xx kk 3 xx 1 xx 0. xx 1 xx 2 xx mm ) [0, rr kk 1 uuuuuu] Range of negative numbers for (ss xx kk 2 xx kk 3 xx 1 xx 0. xx 1 xx 2 xx mm ) [ (rr kk 1 uuuuuu), 0] 10

Negative Numbers: Signed-Magnitude Problems Two zeros 0000...0 1000...0 Difficulties in subtraction If X>Y, X-Y is ok. However, Y-X is -(X-Y), so we should compute X-Y, then set the MSB to 1. 11

Negative Numbers: Complement Represent Y by R Y. Then, ( Y) = R (R Y) = Y. If X>Y>0, Y X = Y + (R X) = R (X Y) = X Y. Two requirements When X>Y>0, X Y = X + (R Y) = R + (X Y) should be X Y. Computation of R Y should be simple. Notation xx ii = rr 1 xx ii XX = (xx kk 1, xx kk 2,, xx 0, xx 1,, xx mm ) XX + XX = ( rr 1, rr 1,, (rr 1)) XX + XX + uuuuuu = rr kk 12

Negative Numbers: Complement One s complement (Diminished-radix complement) RR = rr kk uuuuuu XX = RR XX = XX When X>Y>0, YY XX = YY + RR XX = RR XX YY = (YY XX) When X>Y>0, XX YY = XX + RR YY = RR + XX YY = rr kk + XX YY uuuuuu = XX YY uuuuuu This requires a correction step (add ulp). When X>0, Y>0, XX YY = RR XX + RR YY = RR + RR XX + YY = rr kk + RR XX + YY = RR XX + YY = (XX + YY) Two s complement (Radix complement) RR = rr kk XX = RR XX = XX + uuuuuu When X>Y>0, YY XX = YY + RR XX = RR YY XX = (YY XX) When X>Y>0, XX YY = XX + RR YY = RR + XX YY = rr kk + XX YY = XX YY When X>0, Y>0, XX YY = RR XX + RR YY = RR + RR XX + YY = rr kk + RR XX + YY = RR XX + YY = (XX + YY) 13

Two s Complement Representation One zero 000...0 A negative number that does not have a positive equivalent 100...0 Range [ 2 nn 1, 2 nn 1 uuuuuu] XX = xx nn 1 2 nn 1 + nn 2 ii=0 xx ii 2 ii Proof) If xx nn 1 = 0 (positive), XX = nn 2 ii=0 xx ii 2 ii = xx nn 1 2 nn 1 + nn 2 xx ii 2 ii If xx nn 1 = 1 (negative), XX = XX + uuuuuu = [ nn 1 ii=0 xx ii 2 ii + 1] = ii=0 nn 1 1 xx ii 2 ii + 1 = 2 nn 1 nn 1 ii=0 xx ii 2 ii + 1 nn 1 nn 2 = 2 nn + ii=0 xx ii 2 ii = 2 nn 1 + ii=0 xx ii 2 ii ii=0. 14

One s Complement Representation Two zeros 000...0 111...1 Range [ 2 nn 1 uuuuuu, 2 nn 1 uuuuuu ] XX = xx nn 1 2 nn 1 uuuuuu + nn 2 xx ii 2 ii ii=0 Proof) If xx nn 1 = 0 (positive), XX = ii=0 xx ii 2 ii = xx nn 1 (2 nn 1 uuuuuu) + nn 2 xx ii 2 ii ii=0. nn 2 nn 1 nn 1 If xx nn 1 = 1 (negative), XX = XX = ii=0 xx ii 2 ii = ii=0 1 xx ii 2 ii = 2 nn 1 nn 1 ii=0 xx ii 2 ii = 2 nn + 1 + nn 1 ii=0 xx ii 2 ii = 2 nn 1 + 1 + nn 2 ii=0 xx ii 2 ii = xx nn 1 (2 nn 1 uuuuuu) + ii=0 nn 2 xx ii 2 ii 15

Addition and Subtraction Signed-magnitude 0 1 0 1 1 (11) + 0 0 0 1 0 (2) = 0 1 1 0 1 (13) 0 1 0 1 1 (11) + 0 0 1 1 0 (6) = 1 0 0 0 1 (-1) 1 0 0 1 1 (-3) + 1 0 1 0 1 (-5) =1 0 1 0 0 0 (+8) 1 1 0 0 0 (-8) + 1 1 0 0 1 (-9) =1 1 0 0 0 1 (-1) overflow overflow overflow 0 1 1 0 1 (13) + 1 1 0 0 0 (-8) = 1 0 0 1 0 1 (5) 1 1 1 0 1 (-13) + 0 1 0 0 0 (8) = 1 0 0 1 0 1 (+5) As shown above, addition and subtraction of signed-magnitude numbers need corrections. 16

Addition and Subtraction Two s complement 0 1 0 1 1 (11) + 0 0 0 1 0 (2) = 0 1 1 0 1 (13) 0 1 0 1 1 (11) + 0 0 1 1 0 (6) = 1 0 0 0 1 (-15) 1 1 1 0 1 (-3) + 1 1 0 1 1 (-5) =1 1 1 0 0 0 (-8) 1 1 0 0 0 (-8) + 1 0 1 1 1 (-9) =1 0 1 1 1 1 (-17) overflow indicator overflow indicator 0 1 1 0 1 (13) + 1 1 0 0 0 (-8) = 1 0 0 1 0 1 (5) 1 0 0 1 1 (-13) + 0 1 0 0 0 (8) = 1 1 0 1 1 (-5) 17

Arithmetic Shift Operations For given {xx nn 1, xx nn 2,, xx 1, xx 0 } Signed-magnitude xx nn 1, 0, 0,, 0, xx nn 2,, xx 1, xx 0, 0, 0, Two s complement xx nn 1, xx nn 1,, xx nn 1, xx nn 1, xx nn 2,, xx 1, xx 0, 0, 0, One s complement xx nn 1, xx nn 1,, xx nn 1, xx nn 1, xx nn 2,, xx 1, xx 0, xx nn 1, xx nn 1, 18

Supplementary Materials

Arithmetic Shift Operations Derivation of the extension of the two s complement XX = XX nn 1 0 = {xx nn 1, xx nn 2,, xx 1, xx 0 } If X>0, it is the same as the signed-magnitude case. If X<0 (if X -2 n ), XX = XX nn 1 0 = xx nn 1, xx nn 2,, xx 1, xx 0 XX = {XX nn 1 0 + uuuuuu 0 } ( XX) ext = 00 0 XX nn 1 0 + uuuuuu 0 00 0 = 00 0 KK 00 0 XX ext = 00 0 KK 00 0 + uuuuuu mm = 11 1 KK 11 1 + uuuuuu mm = 11 1 KK + uuuuuu 0 00 0 = 11 1 2 nn KK 00 0 = 11 1 2 nn XX nn 1 0 + uuuuuu 0 00 0 = 11 1 XX nn 1 0 00 0 XX ext = xx nn 1 xx nn 1 xx nn 1, xx nn 2,, xx 1, xx 0 00 0 If X=2 n, we can directly prove it. 20

Arithmetic Shift Operations Derivation of the extension of the one s complement XX = XX nn 1 0 = {xx nn 1, xx nn 2,, xx 1, xx 0 } If X>0, it is the same as the signed-magnitude case. If X<0, XX = XX nn 1 0 = xx nn 1, xx nn 2,, xx 1, xx 0 XX = {XX nn 1 0 } ( XX) ext = 00 0 XX nn 1 0 00 0 XX ext = 00 0 XX nn 1 0 00 0 = 11 1 XX nn 1 0 11 1 XX ext = xx nn 1 xx nn 1 xx nn 1, xx nn 2,, xx 1, xx 0 xx nn 1 xx nn 1 21