Number Representation Part 1 ECE 645: Lecture 4. Required Reading Chapter 1, Numbers and Arithmetic, Sections 1.1-1.6 Chapter 2, Representing Signed Numbers.

Slides:



Advertisements
Similar presentations
HEXADECIMAL NUMBERS Code
Advertisements

COE 202: Digital Logic Design Signed Numbers
Radix Conversion Given a value X represented in source system with radix  s, represent the same number in a destination system with radix  d Consider.
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Assembly Language and Computer Architecture Using C++ and Java
Copyright 2008 Koren ECE666/Koren Part.1.1 Israel Koren Spring 2008 UNIVERSITY OF MASSACHUSETTS Dept. of Electrical & Computer Engineering Digital Computer.
Assembly Language and Computer Architecture Using C++ and Java
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Number Systems Lecture 02.
Fixed-Point Negative Numbers Two Common Forms: 1.Signed-Magnitude Form 2.Complement Forms Signed-Magnitude Numbers First Digit is Sign Digit, Remaining.
Connecting with Computer Science 2 Objectives Learn why numbering systems are important to understand Refresh your knowledge of powers of numbers Learn.
Binary Representation and Computer Arithmetic
Dr. Bernard Chen Ph.D. University of Central Arkansas
Data Representation Number Systems.
ES 244: Digital Logic Design Chapter 1 Chapter 1: Introduction Uchechukwu Ofoegbu Temple University.
ECE 8053 Introduction to Computer Arithmetic (Website: Course & Text Content: Part 1: Number Representation.
Numeral Systems Subjects: Numeral System Positional systems Decimal
Data Representation – Binary Numbers
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
Computer Architecture Lecture 3: Logical circuits, computer arithmetics Piotr Bilski.
Logic and Digital System Design - CS 303
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
1 Digital Technology and Computer Fundamentals Chapter 1 Data Representation and Numbering Systems.
Computer Architecture
Lecture Overview Introduction Positional Numbering System
Data Representation and Computer Arithmetic
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
Computer Arithmetic — Number Representation EPFL – I&C – LAP EPFL – CSDA and UC Davis – ACSEL.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
Number Representation Part 1 Fixed-Radix Unsigned Representations ECE 645: Lecture 1.
Representation of Data Ma King Man. Reference Text Book: Volume 2 Notes: Chapter 19.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
Chapter 2 Binary Values and Number Systems. 2 2 Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645,
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
Fixed and Floating Point Numbers Lesson 3 Ioan Despi.
ECE 8053 Introduction to Computer Arithmetic (Website: Course & Text Content: Part 1: Number Representation.
CSC 221 Computer Organization and Assembly Language
Topic 1 – Number Systems. What is a Number System? A number system consists of an ordered set of symbols (digits) with relations defined for addition,
Data Representation, Number Systems and Base Conversions
Number Representation Part 2 Fixed-Radix Signed Representations Floating Point Representations Little-Endian vs. Big-Endian Representations Galois Field.
Computer Organization and Design Information Encoding II Montek Singh Wed, Aug 29, 2012 Lecture 3.
Number Systems & Operations
Lecture 2 Binary Arithmetic Topics Terminology Fractions Base-r to decimal Unsigned Integers Signed magnitude Two’s complement August 26, 2003 CSCE 211.
Unconventional Fixed-Radix Number Systems
FAMU-FSU College of Engineering 1 Part III The Arithmetic/Logic Unit.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
FAMU-FSU College of Engineering 1 Computer Architecture EEL 4713/5764, Spring 2006 Dr. Michael Frank Module #9 – Number Representations.
ECE 2110: Introduction to Digital Systems
Number Representation Part 1 ECE 645: Lecture 4. Required Reading Chapter 1, Numbers and Arithmetic, Sections Chapter 2, Representing Signed Numbers.
Integer Operations Computer Organization and Assembly Language: Module 5.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Addition and Subtraction
Number Representation
Part III The Arithmetic/Logic Unit
Fixed-Point Representations.
Number Representation
Data Structures Mohammed Thajeel To the second year students
Data Representation Data Types Complements Fixed Point Representation
Data Representation in Computer Systems
ECEG-3202 Computer Architecture and Organization
Presentation transcript:

Number Representation Part 1 ECE 645: Lecture 4

Required Reading Chapter 1, Numbers and Arithmetic, Sections Chapter 2, Representing Signed Numbers B. Parhami, Computer Arithmetic: Algorithms and Hardware Design

Historical Representations: Ancient Egyptians Numerals (1) –~4000 BC –“Sum of Symbols” = (34) 10

Historical Representations: Ancient Egyptians Numerals (2) What number does this stone carving from Karnak represent?

Historical Representations: Ancient Egyptians Numerals (3)

Historical Representations: Ancient Egyptians Numerals (4) Symbol for a fraction (part): Special symbols for most commonly used fractions:

–First known positional system –3100 BC –Radix 60 (sexagesimal) –Two symbols: = 1 = 10 Historical Representations: Ancient Babylonian Numerals (1) − Integers and fractions were represented identically - a radix point was not written but rather made clear by context

Babylonian Numerals: Example 1 x x x 60 0 = (4,856) 10

Historical Representations: Ancient Babylonian Numerals (2) Digits from 1 to 59

Positional Code with Zero Zero Represented by Space –Partial solution –What about trailing zeros? Babylonians Introduced New Symbol – or –4th to 1st Century BC Zero Allows Representation of Fractions –Fractions started with zero

Mixed System Roman Numerals –Sum of all symbols –I=1 V=5 X=10 L=50 C=100 D=500 M=1000 –Difficult to do arithmetic e.g., MCDXLVII - IX ?

Hindu-Arabic Numeral System Brahmi numerals, India, 400 BC-400 AD Evolution of numerals in early Europe

Positional Code Decimal System –Documented in the 9th century –Position of coefficient determines its value –Coefficient in position is multiplied by radix (10) raised to the power determined by its position, e.g.,

Migration of Positional Notation ~750 AD –Zero spread from India to Arabic countries ~1250 AD –Zero spread to Europe Importance of Zero –Ease of arithmetic which leads to improved commerce

Binary Number System Binary –Positional number system –Two symbols, B = { 0, 1 } –Easily implemented using switches –Easy to implement in electronic circuitry –Algebra invented by George Boole ( ) allows easy manipulation of symbols

16 Modern Arithmetic and Number Systems Modern number systems used in digital arithmetic can be broadly classified as: Fixed-point number representation systems Integers Rational numbers of the form x = a/2 f, a is an integer, f is a positive integer Floating-point number representation systems x * b E, where x is a rational number, b the integer base, and E the exponent Note that all digital numbers are eventually coded in bits {0,1} on a computer

17 fixed point floating point Encoding Numbers in 4-Bits

Number system Positional Non-positional Fixed-radixMixed-radix ConventionalUnconventional Signed-digit Non-redundantRedundant Binary Decimal Hexadecimal Classification of number systems (1)

Classification of number systems (2) Positional w i - weight of the digit x i Fixed-radix r - radix of the number system Conventional fixed-radix r integer, r > 0 x i  {0, 1, …, r-1}

Classification of number systems (3) Unconventional fixed-radix x i  {- , …,  } Non-redundant number of digits =  +  + 1  r Redundantnumber of digits =  +  + 1 > r Signed-digit  >0  negative digits

Example of a mixed-radix positional system?

What is it?

Samrat Yantra in Jantar Mantar - Jaipur, India - The largest sundial in the world - 90 feet (27 m) tall - Conceived by Maharaja Sawai Raja Jai Singh II - Built of local stone and marble The style's horizontal angle is equal the sundial's geographical latitude 27° north - The time is read by observing where the shadow is sharpest at the time - Accuracy of 2 seconds - Reconstructed in 1901

Jantar Mantar - Jaipur, India Original Units of Time - 1 day = 60 ghadis (1 ghadi = 24 minutes) - 1 ghadi = 60 pals (1 pal = 24 seconds) - 1 pal = 4 breaths (1 breath = 6 seconds) Original weights: 60*60*4 60*4 4 breaths day ghadi pal Current weights: 24*60*60 60*60 60 seconds day hour minute

Integral and fractional part X = x k-1 x k-2 … x 1 x 0. x -1 x -2 … x -l Integral partFractional part Radix point NOT stored in the register understood to be in a fixed position Fixed-point representation

Fixed-Radix Conventional (Unsigned) Representations

29 Fixed Point Number system Positional Non-positional Fixed-radixMixed-radix Conventional (unsigned) Unconventional (signed) Signed-digit Non-redundantRedundant Binary Decimal Hexadecimal Fixed-Radix Conventional Number Systems

Range of numbers Decimal X = (x k-1 x k-2 … x 1 x 0.x -1 … x -l ) 10 X min X max 10 k l 0 Binary Number system X = (x k-1 x k-2 … x 1 x 0.x -1 … x -l ) k - 2 -l Conventional fixed-radix X = (x k-1 x k-2 … x 1 x 0.x -1 … x -l ) r 0r k - r -l ulp = r -l Notation: unit in the least significant position unit in the last position

Number of digits Number system Number of digits in the integer part necessary to cover the range 0..X max Decimal Binary Conventional fixed-radix

32 Radix Conversion Option 1) Radix conversion, using arithmetic in the old radix r Convenient when converting from r = 10 or familiar radix u =w. v = ( x k–1 x k–2... x 1 x 0. x –1 x –2... x –l ) r Old =( X K–1 X K–2... X 1 X 0. X –1 X –2... X –L ) R New Option 2) Radix conversion, using arithmetic in the new radix R Convenient when converting to R = 10 or familiar radix Whole partFractional part Example: (31) eight = (25) ten From: Parhami, Computer Arithmetic: Algorithms and Hardware Design Two methods:

33 Option 1: Arithmetic in old radix r Converting whole part w:(105) ten = (?) five Repeatedly divide by fiveQuotientRemainder Therefore, (105) ten = (410) five Converting fractional part v:( ) ten = (410.?) five Repeatedly multiply by five Whole Part Fraction Therefore, ( ) ten  ( ) five From: Parhami, Computer Arithmetic: Algorithms and Hardware Design

Radix Conversion of the Integral Part X I = (x k-1 x k-2 … x 1 x 0 ) R = = R - destination radix = ((...((x k-1 R + x k-2 ) R + x k-3 ) R + … + x 2 ) R + x 1 ) R + x 0 Quotient Remainder (...((x k-1 R + x k-2 ) R + x k-3 ) R + … + x 2 ) R + x 1 x0x0...((x k-1 R + x k-2 ) R + x k-3 ) R + … + x 2 x1x1 x k-1 x k-2 x k-1 0 ………. x k-1 R + x k-2 x k-3

Radix Conversion of the Fractional Part X F = (. x -1 x -2 … x -l+1 x -l ) R = = R - destination radix = R -1 (x -1 + R -1 (x -2 + R -1 (…. + R -1 ( x -l+1 + R -1 x -l )….))) Integer partFractional part x -1 R -1 (x -2 + R -1 (….. + R -1 ( x -l+1 + R -1 x -l )….)) R -1 (….. + R -1 ( x -l+1 + R -1 x -l )….) x -2 x -l+1 R -1 x -l x -l 0 ………. x -l+2 R -1 ( x -l+1 + R -1 x -l )

36 Option 2: Arithmetic in new radix R Converting (22033) five = (?) ten ((((2  5) + 2)  5 + 0)  5 + 3)  |-----| : : : : 10 : : : : | | : : : 12 : : : | | : : 60 : : | | : 303 : | | 1518 Converting fractional part v: ( ) five = (105.?) ten ( ) five  5 5 =(22033) five =(1518) ten 1518 / 5 5 =1518 / 3125 = Therefore, ( ) five = ( ) ten Horner’s rule or formula From: Parhami, Computer Arithmetic: Algorithms and Hardware Design

37 Option 2 cont'd: Horner's rule for fractions Converting fractional part v: ( ) five = (?) ten (((((3 / 5) + 3) / 5 + 0) / 5 + 2) / 5 + 2) / 5 |-----| : : : : 0.6 : : : : | | : : : 3.6 : : : | | : : 0.72 : : | | : : | | | | Horner’s rule or formula From: Parhami, Computer Arithmetic: Algorithms and Hardware Design Horner’s rule is also applicable: Proceed from right to left and use division instead of multiplication

38 r=b g  b  R=b G 4=2 2  2  8=2 3 ( ) 4 = ( ) 2 = (261.62) 8 Radix Conversion Shortcut for r=b g, R=b G Trick here is to first convert to a number in radix b, then to R Cluster in groups of 3 (because 2 3 = 8) moving away from binary point

Signed Number Representations

Representations of signed numbers Signed-magnitude Biased Complement Radix-complement Diminished-radix complement (Digit complement) Two’s complementOne’s complement r=2

Signed- magnitude Biased Two’s complement One’s complement

Signed-magnitude representation of signed numbers Advantages: Disadvantages: conceptual simplicity symmetric range: -(2 k-1 -1).. -(2 k-1 -1) simple negation addition of numbers with the same sign and with a different sign handled differently 0k-2k-1 sign magnitude

Biased (excess-B) representation of signed integers B = 2 k-1, k=4 R(X) = X + B -2 k-1 ≤ X ≤ 2 k-1 -1 X R(X) R

Signed number X Unsigned Representation R(X) Bit vector (x k-1 x k-2...x 0.x -1...x -l ) Binary mapping Representation mapping Biased representation with radix 2

Complement Signed Number Representations

Signed number X Unsigned Representation R(X) Bit vector (x k-1 x k-2...x 0.x -1...x -l ) Binary mapping Representation mapping Complement representations with radix 2

1 – x i = x i 1 – x i xixi xixi Useful dependencies |X| = X when X  0 - X when X < 0

One’s complement transformation OC(A) = A = 2 k – 2 -l - A For  0 0  OC(A)  2 k – 2 -l OC(OC(A)) = A def k-1 k l –A k-1 A k-2 … A 0. A -1 A A -l Properties:

One’s Complement Representation of Signed Numbers R(X) = X for X > 0 0 or OC(0) for X = 0 OC(|X|) for X < 0 For –(2 k-1 – 2 -l )  X  2 k-1 – 2 -l 0  R(X)  2 k – 2 -l def

One’s complement representation of signed integers X k=4 X>00 X<0 X+2 k -1 = 2 k -1 - |X| 0, 2 k -1

One’s complement representation of signed numbers

Two’s complement transformation (1) A + 2 -l = 2 k – A for A > 0 For  0 def Properties: TC(A) = 0 for A = 0 0  TC(A)  2 k – 2 -l TC(TC(A)) = A 2 k – A = 2 k – A – 2 -l + 2 -l = = (2 k – 2 -l – A)+2 -l = A + 2 -l

Two’s complement transformation (2) For  0 A + 2 -l mod 2 k = 2 k – A mod 2 k def TC(A) =

Two’s Complement Representation of Signed Numbers R(X) = X for X  0 TC(|X|) for X < 0 For –2 k-1  X  2 k-1 – 2 -l 0  R(X)  2 k – 2 -l def

Two’s complement representation of signed integers X k=4 X>00 X<0 X+2 k = 2 k - |X| 0

Two’s complement representation of signed integers

Signed-magnitude representation of signed numbers X k=4 X>00X<0 | X|+2 k-1 = -X+2 k-1 0, 2 k-1

Signed-magnitude representation of signed numbers

Biased representation of signed numbers X+BX+B B = 2 k-1, k=4 X>00X<0 X+BX+B B

Biased representation of signed numbers

Arithmetic Operations in Signed Number Representations

Unsigned addition vs. signed addition Machine Programmer Unsigned mind Signed mind weight carry XYSXYS + = FA x0x0 y0y0 s0s0 c1c1 x1x1 y1y1 s1s1 c2c2 x2x2 y2y2 s2s2 c3c3 x3x3 y3y3 s3s3 c4c4 x4x4 y4y4 s4s4 c5c5 x5x5 y5y5 s5s5 c6c6 x6x6 y6y6 s6s6 c7c7 x7x7 y7y7 s7s7 c8c8

Out of range flags C = 1 if result > MAX_UNSIGNED or result < 0 0 otherwise where MAX_UNSIGNED = for 8-bit operands for 16-bit operands V = 1 if result > MAX_SIGNED or result < MIN_SIGNED 0 otherwise where MAX_SIGNED = for 8-bit operands for 16-bit operands MIN_SIGNED = -2 7 for 8-bit operands for 16-bit operands Carry flag - C Overflow flag - V out-of-range for unsigned numbers out-of-range for signed numbers

Overflow for signed numbers Indication of overflow Positive + Positive = Negative Negative + Negative = Positive Formulas Overflow 2’s complement = x k-1 y k-1 s k-1 + x k-1 y k-1 s k-1 = = c k  c k-1

Two’s complement representation of signed integers

Addition of Signed and Unsigned Numbers C=1 and V= ≠ ≠8 C=0 and V=

Addition of Signed and Unsigned Numbers C=0 and V= ≠ C=1 and V= ≠7

Can replace this with k xor gates Two's Complement Adder/Subtractor Architecture

Arithmetic Shift Two’s complement Sh.L { = +5} = = +10 Sh.L { = -5} = = -10 Sh.L { = +10} = = - 12 overflow Sh.R { = +5} = = +2 rem 1 Sh.R { = -5} = = -3 rem 1 Shift left may cause overflow Shift right requires sign extension

Addition and subtraction One’s complement Numbers of the same signNumbers of the opposite sign end-arround carry Disadvantage: Need another adder after the addition is complete!

One’s complement representation of signed numbers

Addition and subtraction Signed-magnitude Numbers of the same signNumbers of the opposite sign sign bitmagnitude carry = overflow sign bitmagnitude + 11 > –

Signed Number Representations Summary

Representing k-bit signed binary numbers Representation for X>0 Representation for X<0 Representation for 0 Representation Signed- magnitude X 0, 2 k-1 2 k-1 +|X| Biased X+BX+B B X+BX+B Complement X M-|X|=M+X 0, M mod 2 k Two’s complement One’s complement X X 2 k -|X|= 2 k -ulp-|X|= 0 0, 2 k -ulp typical B=2 k-1 or 2 k-1 -ulp

Value of a number in the signed representations Representation Value of (x k-1 x k-2 … x 1 x 0.x -1 … x -l ) Signed- magnitude Biased Two’s complement One’s complement

Extending the number of bits of a signed number x k-1 x k-2 … x 1 x 0. x -1 x -2 … x -l y k’-1 y k’-2 … y k y k-1 y k-2 … y 1 y 0. y -1 y -2 … y -l y -(l+1) … y -l’ X Y signed-magnitude x k x k-2 … x 1 x 0. x -1 x -2 … x -l two’s complement x k-1 x k-1 x k-1...x k-1 x k-2 … x 1 x 0. x -1 x -2 … x -l one’s complement x k-1 x k-1 x k-1...x k-1 x k-2 … x 1 x 0. x -1 x -2 … x -l x k-1....x k-1 biased x k-2 … x 1 x 0. x -1 x -2 … x -l x k-1

Generalized Complement Representation

Generalized complement representation of signed integers M-N > P M ≥ N+P+1

Generalized complement representation of signed integers