Data Representation Part I Representing Numbers l l
Data Representation Part I
Representing Numbers l l l 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 l l (1) addition of two integers (2) determination of additive inverse
l l l 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
Binary Representation l l 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
Little-Endian vs. Big-Endian l l Numbering the bits from right to left, beginning with zero is called Little Endian byte order. Intel 80 x 86 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. Sun. Sparc and Macintosh use the Big. Endian byte ordering.
Representation of Integers l l l Unsigned Integer Representation Sign Magnitude Complement Representation Biased Representation Sign Extension
Unsigned Integer Representation l l l 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
Sign Magnitude l 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. x l xxxx A 0 in the sign bit means positive, and a 1 means negative
l Given an n+1 -bit sign magnitude number the range of values that it can represent is -(2 n-1) to +(2 n-1) l Sign magnitude representation associates a sign bit with a magnitude that represents zero, thus it has two distinct representation of zero: 0000 and 10000000 sign bit magnitude
Complement Representation l l l 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
One’s Complement l l l 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
Example 9. 1 0000 0011 (3) 1111 1100 (-3) 1110 1000 (-23) 0001 0111 (23) 0000 (0) 1111 (0) Note: There are two representations of zero
Two’s complement l l l 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
Example 9. 2 010001 (17) take 101110 1 -----101111 (-17) 1101000 (-24) the 1’s complement 0010111 1 ------0011000 (24)
l l l 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.
Biased Representation l 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) l 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 l
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 pattern 000 001 010 011 100 101 110 111 integer represented (in decimal) -4 -3 -2 -1 0 1 2 3
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 = 610 Its value in biased-127 is: 6 - 127 = -121
Sign Extension l For integer representations, the sizes are commonly 8, 16, 32 and 64. l 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 l
Sign Extension - Unsigned l Place the original integer into the least significant portion and stuff the remaining positions with 0’s. xxxx 0000 xxxx 8 bits 16 bits
Sign Extension - Signed l l 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 s 0000 xxxxxxx
Sign Extension - complement l For positive number, a 0 is used to stuff The original number is the remaining positions. 0 xxxxxxx placed into the least significant portion 00000 xxxxxxx l For negative number, a 1 is used to stuff the remaining positions. The original number is 1 xxxxxxx 11111 xxxxxxx placed into the least significant portion
- Slides: 22