ECE 645: Lecture 4 Number Representation Part 1 Fixed-Point Representations. Endianness.
Required Reading B. Parhami, Computer Arithmetic: Algorithms and Hardware Design Chapter 1, Numbers and Arithmetic, Sections 1.1-1.6 Chapter 2, Representing Signed Numbers Endianness, from Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/Endianness
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:
Historical Representations: Ancient Babylonian Numerals (1) – First known positional system – 3100 BC – Radix 60 (sexagesimal) – Two symbols: = 1 = 10 − Integers and fractions were represented identically - a radix point was not written but rather made clear by context
Babylonian Numerals: Example 1 x 60 2 20 x 60 1 56 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., 3 2 1 0 ( ) 4 10 * 8 10 * 5 10 * 6 10 * 4 856 , + + + = 10
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 (1815-1864) allows easy manipulation of symbols 3 2 1 0 ( ) ( ) 0101 0 * 2 1 * 2 0 * 2 1 * 2 5 = + + + = 2 10
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 16
Encoding Numbers in 4-Bits − 16 − 14 − 12 − 10 − 8 − 6 − 4 − 2 0 2 4 6 8 10 12 14 16 Number format Unsigned integers Signed-magnitude ± fixed 3 + 1 fixed-point, xxx.x point Signed fraction, ± .xxx ± 2’s-compl. fraction, x.xxx e s e 2 + 2 floating-point, s × 2 e in [ − 2, 1], s in [0, 3] floating point log x 2 + 2 logarithmic (log = xx.xx ) 17
Classification of number systems (1) Number system Non-positional Positional Fixed-radix Mixed-radix Conventional Unconventional Binary Signed-digit Decimal Hexadecimal Non-redundant Redundant
Classification of number systems (2) Positional k 1 − = ∑ X x i w ⋅ w i - weight of the digit x i i i l = − Fixed-radix k 1 − = ∑ i X x i r ⋅ r - radix of the number system i l = − Conventional fixed-radix r integer, r > 0 k 1 − = ∑ i X x i r ⋅ x i ∈ {0, 1, …, r -1} i l = −
Classification of number systems (3) Unconventional fixed-radix k 1 − = ∑ i X x i r ⋅ x i ∈ {- α , …, β } i l = − Signed-digit α >0 ⇒ negative digits Non-redundant number of digits = α + β + 1 ≤ r Redundant number of digits = α + β + 1 > r
Example of a mixed-radix positional system?
What is it?
What is it?
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 1728-1734 - 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
Fixed-point representation Integral and fractional part X = x k -1 x k -2 … x 1 x 0 . x -1 x -2 … x - l Integral part Fractional part Radix point • NOT stored in the register • understood to be in a fixed position
Fixed-Radix Conventional (Unsigned) Representations
Fixed-Radix Conventional Number Systems Fixed Point Number system Non-positional Positional Fixed-radix Mixed-radix Conventional Unconventional (signed) (unsigned) Binary Signed-digit Decimal Hexadecimal Non-redundant Redundant 29
Range of numbers X min X max Number system Decimal X = ( x k -1 x k -2 … x 1 x 0 . x -1 … x - l ) 10 0 10 k - 10 - l Binary X = ( x k -1 x k -2 … x 1 x 0 . x -1 … x - l ) 2 2 k - 2 - l 0 Conventional fixed-radix X = ( x k -1 x k -2 … x 1 x 0 . x -1 … x - l ) r 0 r k - r - l Notation: u nit in the l east significant p osition ulp = r - l u nit in the l ast p osition
Number of digits Number of digits in the integer part necessary to cover the range Number system 0.. X max k log X 1 Decimal = + = ⎣ ⎦ 10 max log ( X 1 ) = + ⎡ ⎤ 10 max Binary k log X 1 = + = ⎣ ⎦ 2 max log ( X 1 ) = + ⎡ ⎤ 2 max k log X 1 Conventional = + = ⎣ ⎦ r max fixed-radix log ( X 1 ) = + ⎡ ⎤ r max
Radix Conversion Whole part Fractional part 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 Example: (31) eight = (25) ten Two methods: Option 1) Radix conversion, using arithmetic in the old radix r Convenient when converting from r = 10 or familiar radix Option 2) Radix conversion, using arithmetic in the new radix R Convenient when converting to R = 10 or familiar radix 32 From: Parhami, Computer Arithmetic: Algorithms and Hardware Design
Option 1: Arithmetic in old radix r Converting whole part w : (105) ten = (?) five Repeatedly divide by five Quotient Remainder 105 0 21 1 4 4 0 Therefore, (105) ten = (410) five Converting fractional part v : (105.486) ten = (410.?) five Repeatedly multiply by five Whole Part Fraction .486 2 .430 2 .150 0 .750 3 .750 3 .750 Therefore, (105.486) ten ≅ (410.22033) five 33 From: Parhami, Computer Arithmetic: Algorithms and Hardware Design
Radix Conversion of the Integral Part R - destination radix k 1 − ∑ X I = ( x k -1 x k -2 … x 1 x 0 ) R = = i x ⋅ i R i 0 = = ((...(( x k -1 R + x k -2 ) R + x k -3 ) R + … + x 2 ) R + x 1 ) R + x 0 Quotient Remainder x 0 (...(( x k -1 R + x k -2 ) R + x k -3 ) R + … + x 2 ) R + x 1 x 1 ...(( x k -1 R + x k -2 ) R + x k -3 ) R + … + x 2 ………. ………. x k-3 x k -1 R + x k -2 x k -1 x k -2 x k -1 0
Radix Conversion of the Fractional Part R - destination radix 1 − ∑ i x ⋅ i R X F = (. x -1 x -2 … x - l +1 x - l ) R = = i l = − = R -1 ( x -1 + R -1 ( x -2 + R -1 (…. + R -1 ( x -l+1 + R -1 x -l )….))) Integer part Fractional part x -1 R -1 ( x -2 + R -1 (….. + R -1 ( x -l+1 + R -1 x -l )….)) x -2 R -1 (….. + R -1 ( x -l+1 + R -1 x -l )….) ………. ………. x -l+2 R -1 ( x -l+1 + R -1 x -l ) x -l+1 R -1 x -l x -l 0
Option 2: Arithmetic in new radix R Converting fractional part v : (410.22033) five = (105.?) ten (0.22033) five × 5 5 = (22033) five = (1518) ten 1518 / 5 5 = 1518 / 3125 = 0.48576 Therefore, (410.22033) five = (105.48576) ten Converting (22033) five = (?) ten � ((((2 × 5) + 2) × 5 + 0) × 5 + 3) × 5 + 3 � � |-----| : : : : � � 10 : : : : � � |-----------| : : : � Horner ’ s � 12 : : : � rule or � |---------------------| : : � � 60 : : � formula � |-------------------------------| : � � 303 : � � |-----------------------------------------| � � 1518 � 36 From: Parhami, Computer Arithmetic: Algorithms and Hardware Design
Recommend
More recommend