Presentation is loading. Please wait.

Presentation is loading. Please wait.

Number Representation Part 2 Fixed-Radix Signed Representations Floating Point Representations Little-Endian vs. Big-Endian Representations Galois Field.

Similar presentations


Presentation on theme: "Number Representation Part 2 Fixed-Radix Signed Representations Floating Point Representations Little-Endian vs. Big-Endian Representations Galois Field."— Presentation transcript:

1 Number Representation Part 2 Fixed-Radix Signed Representations Floating Point Representations Little-Endian vs. Big-Endian Representations Galois Field Representations ECE 645: Lecture 2

2 Required Reading Chapter 2, Representing Signed Numbers, Chapter 17, Floating-Point Representations Behrooz Parhami, Computer Arithmetic: Algorithms and Hardware Design J-P. Deschamps, G. Bioul, G. Sutter, Synthesis of Arithmetic Circuits: FPGA, ASIC and Embedded Systems, Chapter 3.2, Integers Chapter 3.3, Real Numbers

3 Recommended Reading (to be covered at the next lecture) Chapter 5, Basic Addition and Counting Behrooz Parhami, Computer Arithmetic: Algorithms and Hardware Design J-P. Deschamps, G. Bioul, G. Sutter, Synthesis of Arithmetic Circuits: FPGA, ASIC and Embedded Systems, Chapter 4.1.1 Basic Algorithm Chapter 11.1 Basic Adder Chapter 11.2 Carry-Chain Adder

4 Signed Number Representations

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

6 7 0111 1111 0111 0111 6 0110 1110 0110 0110 5 0101 1101 0101 0101 4 0100 1100 0100 0100 3 0011 1011 0011 0011 2 0010 1010 0010 0010 1 0001 1001 0001 0001 0 0000 1000 0000 0000 -0 1000 1111 -1 1001 0111 1111 1110 -2 1010 0110 1110 1101 -3 1011 0101 1101 1100 -4 1100 0100 1100 1011 -5 1101 0011 1011 1010 -6 1110 0010 1010 1001 -7 1111 0001 1001 1000 -8 0000 1000 Signed- magnitude Biased Two’s complement One’s complement

7 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

8 Biased (excess-B) representation of signed integers -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 B = 2 k-1, k=4 R(X) = X + B -2 k-1 ≤ X ≤ 2 k-1 -1 X R(X) R

9 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

10 Complement Signed Number Representations

11 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

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

13 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-2... 0 -1 -2... -l 1 1... 1. 1 1... 1 –A k-1 A k-2 … A 0. A -1 A -2... A -l Properties:

14 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

15 One’s complement representation of signed integers -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 X k=4 X>00 X<0 X+2 k -1 = 2 k -1 - |X| 0, 2 k -1

16 One’s complement representation of signed numbers

17 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

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

19 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

20 Two’s complement representation of signed integers -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 X k=4 X>00 X<0 X+2 k = 2 k - |X| 0

21 Two’s complement representation of signed integers

22 Signed-magnitude representation of signed numbers -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 X k=4 X>00X<0 | X|+2 k-1 = -X+2 k-1 0, 2 k-1

23 Signed-magnitude representation of signed numbers

24 Biased representation of signed numbers -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 X+BX+B B = 2 k-1, k=4 X>00X<0 X+BX+B B

25 Biased representation of signed numbers

26 Arithmetic Operations in Signed Number Representations

27 Unsigned addition vs. signed addition Machine Programmer 0 0 0 1 0 0 1 1 1 0 0 0 0 1 0 1 1 0 0 1 1 0 0 0 111 Unsigned mind Signed mind 128 64 32 16 8 4 2 1 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

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

29 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

30 Two’s complement representation of signed integers

31 Addition and subtraction Two’s complement 0 0 1 0 1 5 1 0 1 1 0 -10 -16 8 4 2 1 1 1 0 1 1 -5 Numbers of the same signNumbers of the opposite sign 0 1 0 1 0 10 1 1 0 1 1 -5 -16 8 4 2 1 1 0 0 1 0 1 5 carry but not overflow 1 1 0 1 1 -5 1 0 1 1 0 -10 -16 8 4 2 1 1 1 0 0 0 1 -15 carry but not overflow 0 0 1 1 1 7 0 1 0 1 0 10 -16 8 4 2 1 1 0 0 0 1 -15 no carry but overflow

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

33 Arithmetic Shift Two’s complement Sh.L {00101 2 = +5} = 01010 2 = +10 Sh.L {11011 2 = -5} = 10110 2 = -10 Sh.L {01010 2 = +10} = 10100 2 = - 12 overflow Sh.R {00101 2 = +5} = 00010 2 = +2 rem 1 Sh.R {11011 2 = -5} = 11101 2 = -3 rem 1 Shift left may cause overflow Shift right requires sign extension

34 Addition and subtraction One’s complement Numbers of the same signNumbers of the opposite sign 0 1 0 1 0 10 1 1 0 1 0 -5 -15 8 4 2 1 1 0 0 1 0 0 1 1 0 1 0 -5 1 0 1 0 1 -10 -15 8 4 2 1 1 0 1 1 1 1 + 1 1 0 0 0 0 -15 end-arround carry + 0 0 1 0 1 5 1 Disadvantage: Need another adder after the addition is complete!

35 Arithmetic Shift One’s complement Sh.L {00101 2 = +5} = 01010 2 = +10 Sh.L {11010 2 = -5} = 10101 2 = -10 Sh.L {01010 2 = +10} = 10100 2 = - 11 overflow Sh.R {00101 2 = +5} = 00010 2 = +2 rem 1 Sh.R {11011 2 = -5} = 11101 2 = -2 rem -1 Shift left may cause overflow Shift right requires sign extension

36 Addition and subtraction Signed-magnitude Numbers of the same signNumbers of the opposite sign 0 1 0 1 1 11 0 0 1 1 0 6 sign bitmagnitude + 0 1 0 0 0 1 17 carry = overflow 1 1 0 1 1 -11 0 0 1 1 0 6 sign bitmagnitude + 11 > 6 1 0 1 1 11 0 1 1 0 6 – 0 1 5 1

37

38 Signed Number Representations Summary

39 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

40 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

41 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-1 0 0 0 0 0 0 0 x k-2 … x 1 x 0. x -1 x -2 … x -l 0 0 0 0 0 0 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 0 0 0 0 0 0 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 0 0 0 0 0 0... x k-1

42 Generalized Complement Representation

43 Generalized complement representation of signed integers

44 Generalized complement representation of signed integers

45 Floating Point Representations

46

47

48

49

50

51 The ANSI/IEEE standard floating- point number representation formats IEEE 754 Standard (now being revised to yield IEEE 754R)

52

53 Table 17.1 Some features of the ANSI/IEEE standard floatingpoint number representation formats

54 00017FFEFF7E80 01127254255126128 –1260+127–1+1 Decimal code Hex code Exponent value f = 0: Representation of  0 f  0: Representation of denormals, 0.f  2 –126 f = 0: Representation of  f  0: Representation of NaNs Exponent encoding in 8 bits for the single/short (32-bit) ANSI/IEEE format 1.f  2 e Exponent Encoding

55

56

57 Fig. 17.4 Denormals in the IEEE single-precision format.

58

59

60

61

62

63 Little-Endian vs. Big-Endian Representation of Integers

64 Little-Endian vs. Big-Endian Representation A0 B1 C2 D3 E4 F5 67 89 16 LSB MSB MSB = A0 B1 C2 D3 E4 F5 67 LSB = 89 Big-Endian Little-Endian LSB = 89 0 MAX 67 F5 E4 D3 C2 B1 MSB = A0 address

65 Little-Endian vs. Big-Endian Camps Big-Endian Little-Endian 0 MAX address MSB LSB... LSB MSB... Motorola 68xx, 680x0 Intel IBM Hewlett-Packard DEC VAX Internet TCP/IP Sun SuperSPARC Bi-Endian Motorola Power PC Silicon Graphics MIPS RS 232 AMD

66 Origin of the terms Little-Endian vs. Big-Endian Jonathan Swift, Gulliver’s Travels A law requiring all citizens of Lilliput to break their soft-eggs at the little ends only A civil war breaking between the Little Endians and the Big-Endians, resulting in the Big Endians taking refuge on a nearby island, the kingdom of Blefuscu Satire over holy wars between Protestant Church of England and the Catholic Church of France

67

68 Little-Endian vs. Big-Endian Big-EndianLittle-Endian easier to determine a sign of the number easier to compare two numbers easier to divide two numbers easier to print easier addition and multiplication of multiprecision numbers Advantages and Disadvantages

69 Pointers (1) 89 67 F5 E4 D3 C2 B1 A0 Big-Endian Little-Endian 0 MAX address int * iptr; (* iptr) = 8967;(* iptr) = 6789; iptr+1

70 Pointers (2) 89 67 F5 E4 D3 C2 B1 A0 Big-Endian Little-Endian 0 MAX address long int * lptr; (* lptr) = 8967F5E4;(* lptr) = E4F56789; lptr + 1

71 Polynomial Representation of the Galois Field elements

72 Evariste Galois (1811-1832)

73 Studied the problem of finding algebraic solutions for the general equations of the degree  5, e.g., f(x) = a 5 x 5 + a 4 x 4 + a 3 x 3 + a 2 x 2 + a 1 x+ a 0 = 0 Answered definitely the question which specific equations of a given degree have algebraic solutions On the way, he developed group theory, one of the most important branches of modern mathematics.

74 Evariste Galois (1811-1832) 1829 Galois submits his results for the first time to the French Academy of Sciences Reviewer 1 Augustin-Luis Cauchy forgot or lost the communication 1830Galois submits the revised version of his manuscript, hoping to enter the competition for the Grand Prize in mathematics Reviewer 2 Joseph Fourier – died shortly after receiving the manuscript 1831Third submission to the French Academy of Sciences Reviewer 3 Simeon-Denis Poisson – did not understand the manuscript and rejected it.

75 Evariste Galois (1811-1832) May 1832 Galois provoked into a duel The night before the duel he writes a letter to his friend containing the summary of his discoveries. The letter ends with a plea: “Eventually there will be, I hope, some people who will find it profitable to decipher this mess.” May 30, 1832 Galois is grievously wounded in the duel and dies in the hospital the following day. 1843Galois manuscript rediscovered by Joseph Liouville 1846 Galois manuscript published for the first time in a mathematical journal

76

77 Field Set F, and two operations typically denoted by (but not necessarily equivalent to) + and * Set F, and definitions of these two operations must fulfill special conditions.

78 { set Zp={0, 1, 2, …, p-1}, + (mod p): addition modulo p, * (mod p): multiplication modulo p } Examples of fields Infinite fields Finite fields { R= set of real numbers, + addition of real numbers * multiplication of real numbers }

79 Finite Fields = Galois Fields GF(p) GF(2 m ) Polynomial basis representation Normal basis representation Fast in hardware Arithmetic operations present in many libraries Fast squaring GF(p m ) p – prime p m – number of elements in the field Most significant special cases

80 Elements of the Galois Field GF(2 m ) Binary representation (used for storing and processing in computer systems): Polynomial representation (used for the definition of basic arithmetic operations): A = (a m-1, a m-2, …, a 2, a 1, a 0 ) a i  {0, 1} A(x) =  a i  x i = a m-1  x m-1 + a m-2  x m-2 + …+ a 2  x 2 + a 1  x+a 0  multiplication + addition modulo 2 (XOR) i=0 m-1

81 Addition and Multiplication in the Galois Field GF(2 m ) Inputs A = (a m-1, a m-2, …, a 2, a 1, a 0 ) B = (b m-1, b m-2, …, b 2, b 1, b 0 ) a i, b i  {0, 1} Output C = (c m-1, c m-2, …, c 2, c 1, c 0 ) c i  {0, 1}

82 Addition A  A(x) B  B(x) C  C(x) = A(x) + B(x) = = (a m-1 +b m-1 )  x m-1 + (a m-2 +b m-2 )  x m-2 + …+ + (a 2 +b 2 )  x 2 + (a 1 +b 1 )  x + (a 0 +b 0 ) = = c m-1  x m-1 + c m-2  x m-2 + …+ c 2  x 2 + c 1  x+c 0 Addition in the Galois Field GF(2 m )  multiplication + addition modulo 2 (XOR) c i = a i + b i = a i XOR b i C = A XOR B

83 Multiplication A  A(x) B  B(x) C  C(x) = A(x)  B(x) mod P(X) = c m-1  x m-1 + c m-2  x m-2 + …+ c 2  x 2 + c 1  x+c 0 Multiplication in the Galois Field GF(2 m ) P(x) - irreducible polynomial of the degree m P(x) = p m  x m + p m-1  x m-1 + …+ p 2  x 2 + p 1  x+p 0


Download ppt "Number Representation Part 2 Fixed-Radix Signed Representations Floating Point Representations Little-Endian vs. Big-Endian Representations Galois Field."

Similar presentations


Ads by Google