Presentation is loading. Please wait.

Presentation is loading. Please wait.

Number Representation

Similar presentations


Presentation on theme: "Number Representation"— Presentation transcript:

1 Number Representation
ECE 645: Lecture 1 Number Representation Part 1

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

3 Recommended Reading J-P. Deschamps, G. Bioul, G. Sutter,
Synthesis of Arithmetic Circuits: FPGA, ASIC and Embedded Systems, Chapter 1, Introduction Chapter Weighted systems Chapter 3.2, Integers

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

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

6 Historical Representations: Ancient Egyptians Numerals (3)

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

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

9 Babylonian Numerals: Example
1 x x x 600 = (4,856)10

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

11 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

12 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 ?

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

14 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.,

15 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

16 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

17 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/2f, a is an integer, f is a positive integer Floating-point number representation systems x * bE, 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

18 Encoding Numbers in 4-Bits
fixed point floating point

19 Classification of number systems (1)
Positional Non-positional Fixed-radix Mixed-radix Conventional Unconventional Binary Decimal Hexadecimal Signed-digit Non-redundant Redundant

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

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

22 Fixed-point representation
Integral and fractional part X = xk-1 xk-2 … x1 x0 . x-1 x-2 … x-l Integral part Fractional part Radix point NOT stored in the register understood to be in a fixed position

23 Fixed-Radix Conventional (Unsigned) Representations

24 Fixed-Radix Conventional Number Systems
Fixed Point Number system Positional Non-positional Fixed-radix Mixed-radix Conventional (unsigned) Unconventional (signed) Binary Decimal Hexadecimal Signed-digit Non-redundant Redundant

25 Range of numbers Xmin Xmax Number system Decimal
X = (xk-1 xk-2 … x1 x0.x-1 … x-l)10 10k - 10-l Binary X = (xk-1 xk-2 … x1 x0.x-1 … x-l)2 2k - 2-l Conventional fixed-radix X = (xk-1 xk-2 … x1 x0.x-1 … x-l)r rk - r-l Notation: unit in the least significant position unit in the last position ulp = r-l

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

27 Radix Conversion Whole part Fractional part u = w . v = ( xk–1xk– x1x0 . x–1x– x–l )r Old = ( XK–1XK– X1X0 . X–1X– 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 From: Parhami, Computer Arithmetic: Algorithms and Hardware Design

28 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 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

29 Radix Conversion of the Integral Part
R - destination radix XI = (xk-1 xk-2 … x1 x0)R = = = ((...((xk-1 R + xk-2) R + xk-3 ) R + … + x2 ) R + x1 ) R + x0 Quotient Remainder (...((xk-1 R + xk-2) R + xk-3 ) R + … + x2 ) R + x1 x0 ...((xk-1 R + xk-2) R + xk-3 ) R + … + x2 x1 ………. ………. xk-1 xk-2 xk-1

30 Radix Conversion of the Fractional Part
R - destination radix XF = (. x-1 x-2 … x-l+1 x-l)R = = = 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+1 R-1 x-l x-l ...

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

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

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

34 Signed Number Representations

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

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

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

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

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

40 Signed Number Representations
Complement Signed Number Representations

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

42 Useful dependencies 1 – xi = xi X when X  0 - X when X < 0 xi
1 1 1

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

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

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

46 One’s complement representation of signed numbers

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

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

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

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

51 Two’s complement representation of signed integers

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

53 Signed-magnitude representation of signed numbers

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

55 Biased representation of signed numbers

56 Arithmetic Operations in Signed Number Representations

57 Unsigned addition vs. signed addition
Programmer Machine Unsigned mind Signed mind weight carry 1 1 1 X Y S + = x7 y7 x6 y6 x5 y5 x4 y4 x3 y3 x2 y2 x1 y1 x0 y0 FA FA FA FA FA FA FA FA c8 c7 c6 c5 c4 c3 c2 c1 s7 s6 s5 s4 s3 s2 s1 s0

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

59 Overflow for signed numbers
Indication of overflow Positive + Positive = Negative Negative + Negative = Positive Formulas Overflow2’s complement = xk-1 yk-1 sk-1 + xk-1 yk-1 sk-1 = = ck  ck-1

60 Two’s complement representation of signed integers

61 Addition and subtraction
Two’s complement Numbers of the same sign Numbers of the opposite sign carry but not overflow no carry but overflow carry but not overflow

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

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

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

65 Addition and subtraction
Signed-magnitude Numbers of the same sign Numbers of the opposite sign sign bit magnitude sign bit magnitude + + 17 11 > 6 carry = overflow 1 5

66

67 Signed Number Representations
Summary

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

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

70 Extending the number of bits of a signed number
xk-1 xk-2 … x1 x0 . x-1 x-2 … x-l X Y yk’-1 yk’-2 … yk yk-1 yk-2 … y1 y0 . y-1 y-2 … y-l y-(l+1) … y-l’ signed-magnitude xk xk-2 … x1 x0 . x-1 x-2 … x-l two’s complement xk-1 xk-1 xk xk-1 xk-2 … x1 x0 . x-1 x-2 … x-l one’s complement xk-1 xk-1 xk xk-1 xk-2 … x1 x0 . x-1 x-2 … x-l xk xk-1 biased xk-1 . . . xk-2 … x1 x0 . x-1 x-2 … x-l

71 Generalized Complement Representation

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

73 Generalized complement representation
of signed integers


Download ppt "Number Representation"

Similar presentations


Ads by Google