【文章內(nèi)容簡介】
the remainder is recorded under each quotient. Stop when the quotient is zero. 0 ? 1 ? 2 ? 4 ? 8 ? 17 ? 35 Dec. Binary 1 0 0 0 1 1 Solution Example 2 計算機導論 INTEGER REPRESENTATION( 整數(shù)表示法 ) Integers are whole numbers (., numbers without a fraction). An integer can be positive or negative. ?∞ ←? 0 ?→ +∞ To use puter memory more efficiently, two broad categories of integer representation have been developed: unsigned integers and signed integers . Signed integers may also be represented in three distinct ways. Integer:整數(shù) fraction:分數(shù) unsigned integer:無符號整數(shù) signed integer:帶符號整數(shù) 計算機導論 UNSIGNED INTEGERS FORMAT An unsigned integer is an integer without a sign. Most puters define a constant called the maximum unsigned integer. An unsigned integer ranges between 0 and this constant. The maximum unsigned integer depends on the number of bits the puter allocates to store an unsigned integer. Range: 0 ... (2N1) N is the number of bits allocated to represent one unsigned integer. Number of Bits 8 16 Range 0 . . . 255 0 . . . 65,535 計算機導論 Representation Storing unsigned integers is a straightforward process as outlined in the following step: 1. The number is changed to binary. 2. If the number of bits is less than N, 0s are added to the left of the binary number so that there is a total of N bit. Store 7 in an 8bit memory location(存儲單元) . First change the number to binary 111. Add five 0s to make a total of N (8) bits, 00000111. The number is stored in the memory location. Solution Example 3 計算機導論 Store 258 in a 16bit memory location. First change the number to binary 100000010. Add seven 0s to make a total of N (16) bits, 0000000100000010. The number is stored in the memory location. Solution Example 4 計算機導論 Overflow(溢出) If you try to store an unsigned integer such as 256 in an 8bit memory location, you get a condition called overflow. Decimal 7 234 258 24,760 1,245,678 8bit allocation 00000111 11101010 overflow overflow overflow 16bit allocation 0000000000000111 0000000011101010 0000000100000010 0110000010111000 overflow 計算機導論 Interpretation How do you interpret an unsigned binary representation in decimal? The process is simple. Change the N bits from the binary system to the decimal system. Interpret 00101011 in decimal if the number was stored as an unsigned integer. Using the procedure shown in Figure , the number in decimal is 43. Solution Example 5 計算機導論 SIGNED INTEGERS FORMAT SIGNANDMAGNITUDE FORMAT(原碼) In signandmagnitude representation ?the leftmost bit defines the sign of the number. ?If it is 0, the number is positive. ?If it is 1, the number is negative positive:正數(shù) negative:負數(shù) 計算機導論 SIGNANDMAGNITUDE FORMAT Range: (2N11) —— +(2N11) There are two 0s in signandmagnitude representation: positive and negative. In an 8bit allocation: +0 ? 00000000 0 ? 10000000 Number of Bits 8 16 32 127 0 32767 0 2,147,483,647 0 +0 +127 +0 +32767 +0 +2,147,483,647 Range 計算機導論 Representation Storing signandmagnitude integer is a straightforward process: 1. The number is changed to binary。 the sign is ignored. 2. If the number of bits is less than N1, 0s are added to the left of the number so that there is a total of N1 bits. 3. If the number is positive, 0 is added to the left (to make it N bits). If the number is negative, 1 is added to the left (to make it N bits). 計算機導論 Store +7 in an 8bit memory location using signandmagnitude representation. First change the number to binary 111. Add four 0s to make a total of N1 (7) bits, 0000111. Add an extra zero because the number is positive. The result is: 00000111 Solution Example 6 計算機導論 Store –258 in a 16bit memory location using signandmagnitude representation. First change the number to binary 100000010. Add six 0s to make a total of N1 (15) bits, 000000100000010. Add an extra 1 because the number is negative. The result is: 1000000100000010 Solution Example 7 計算機導論 Interpretation How do you interpret a signandmagnitude binary representation in decimal? The process is simple: 1. Ignore the first (leftmost) bit. 2. Change the N1 bits from binary to decimal as shown at the beginning of the chapter. 3. Attach a + or a – sign to the number based on the leftmost bit. Decimal +7 124 +258 24,760 8bit allocation 00000111 11111100 overflow overflow 16bit allocation 0000000000000111 1000000001111100 0000000100000010 1110000010111000 計算機導論 Interpret 10111011 in decimal if the number was stored as a signandmagnitude integer. Ignoring the leftmost bit, the remaining bits are 0111011. This number in decimal is 59. The leftmost bit is 1, so the number is –59. Solution Example 8 計算機導論 ONE’S COMPLEMENT FORMAT(反碼) ? One’s plement of a number is obtained by changing all 0s to 1s and all 1s to 0s. ? The leftmost bit defines the sign of the number. If it is 0, the number is positive. If it is 1, the number is negative. ? A positive number is presented by it’s SIGNANDMAGNITUDE FORMAT ? A negative number is presented by it’s ONE’S COMPLEMENT FORMAT There are two 0s in one’s plement representation: positive and negative. In an 8bit allocation: +0 ?