Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Representation - Part I. Representing Numbers Choosing an appropriate representation is a critical decision a computer designer has to make The chosen.

Similar presentations


Presentation on theme: "Data Representation - Part I. Representing Numbers Choosing an appropriate representation is a critical decision a computer designer has to make The chosen."— Presentation transcript:

1 Data Representation - Part I

2 Representing Numbers Choosing an appropriate representation is a critical decision a computer designer has to make The chosen representation must allow for efficient execution of primitive operations For general-purpose computers, the representation must allow efficient algorithms for (1) addition of two integers (2) determination of additive inverse

3 With a sequence of N bits, there are 2 N unique representations Each memory cell can hold N bits The size of the memory cell determines the number of unique values that can be represented The cost of performing operations also increases as the size of the memory cell increases It is reasonable to select a memory cell size such that numbers that are frequently used are represented

4 Binary Representation The binary, weighted positional notation is the natural way to represent non-negative numbers SAL and MAL number the bits from right to left, i.e., beginning with 0 as the least significant digit

5 Little-Endian vs. Big-Endian Numbering the bits from right to left, beginning with zero is called Little Endian byte order. Intel 80x86 and DECstation 3100 use the Little Endian byte ordering. Numbering the bits from left to right, beginning with zero is called Big Endian byte order. SunSparc and Macintosh use the Big- Endian byte ordering.

6 Representation of Integers Unsigned Integer Representation Sign Magnitude Complement Representation Biased Representation Sign Extension

7 Unsigned Integer Representation The representation of a non-negative integer using binary, weighted positional notation is called unsigned integer representation Given n bits, it is possible to represent the range of values from 0 to 2 n - 1 For example an 8-bit representation would allow representations that range 0 to 255

8 Sign Magnitude An extra bit in the most significant position is designated as the sign bit which is to the left of an unsigned integer. The unsigned integer is the magnitude. A 0 in the sign bit means positive, and a 1 means negative xxx xxxx x

9 Given an n+1 -bit sign magnitude number the range of values that it can represent is -(2 n -1) to +(2 n -1) Sign magnitude representation associates a sign bit with a magnitude that represents zero, thus it has two distinct representation of zero: 00000000 and 10000000 sign bit magnitude

10 Complement Representation For positive integers, the representation is the same as for sign magnitude For negative numbers, a large bias is added to all negative numbers, creating positive numbers in unsigned representation The bias is chosen so that any negative number representable appears as if it were larger than the largest positive number representable

11 One’s Complement For positive numbers, the representation is the same as for unsigned integers where the most significant bit is always zero The additive inverse of a one’s complement representation is found by inverting each bit. Inverting each bit is also called taking the one’s complement

12 Example 9.1 0000 0011 (3) 1111 1100 (-3) 1110 1000 (-23) 0001 0111 (23) 0000 0000 (0) 1111 1111 (0) Note: There are two representations of zero

13 Two’s complement The additive inverse of a two’s complement integer can be obtained by adding 1 to its one’s complement The two’s complement representation for a negative number is the additive inverse of its positive representation An advantage of two’s complement is that there is only one representation for zero

14 Example 9.2 010001 (17)1101000 (-24) 1011100010111 1 1 ------------- 101111 (-17)0011000 (24) take the 1’s complement

15 In two’s complement, one more negative value than positive value is represented - the most negative number has no additive inverse within a fixed precision. For example, 1000000 has no additive inverse for 8-bit precision. Taking the two’s complement will yield 1000000 which seems its own additive inverse. This is incorrect and is an example of an overflow. Note that computing the additive inverse is a mathematical operation. Taking the complement is an operation on the representation.

16 Biased Representation If the unsigned representation includes integers from 0 to M, then subtracting approximately M/2 from the unsigned interpretation would shift the range from -(M/2) to +(M/2) If a sequence has a value N when interpreted as an unsigned integer, it has a value N-bias interpreted as a biased number Usually the bias is either 2 n or 2 n -1 for an (n+1) bit representation

17 Example 9.3 Assume a 3-bit representation. A possible bias is 2 n-1, which is 4. The following is a 3-bit representation with a bias of 4. bit patterninteger represented (in decimal) 000-4 001-3 010-2 011-1 100 0 101 1 110 2 111 3

18 Example 9.4 Given 0000 0110, what is it’s value in a biased-127 representation. Assume an 8-bit representation. The value of the unsigned integer: 0000 0110 =6 10 Its value in biased-127 is: 6 - 127 = -121

19 Sign Extension For integer representations, the sizes are commonly 8, 16, 32 and 64. It is occasionally necessary to convert an integer representation from one size to another, e.g., from 8 bits to 32 bits. The point is to maintain the same value while changing the size of the representation

20 Sign Extension - Unsigned Place the original integer into the least significant portion and stuff the remaining positions with 0 ’s. xxxxxxxx 00000000xxxxxxxx 8 bits 16 bits

21 Sign Extension - Signed The sign bit of the smaller representation is placed into the sign bit of the larger representation The magnitude is put into the least significant portion and all remaining positions are stuffed with 0 ’s. sxxxxxxx s00000000xxxxxxx

22 Sign Extension - complement For positive number, a 0 is used to stuff the remaining positions. For negative number, a 1 is used to stuff the remaining positions. 0xxxxxxx 000000000xxxxxxx 1xxxxxxx 111111111xxxxxxx The original number is placed into the least significant portion The original number is placed into the least significant portion


Download ppt "Data Representation - Part I. Representing Numbers Choosing an appropriate representation is a critical decision a computer designer has to make The chosen."

Similar presentations


Ads by Google