Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)

Similar presentations


Presentation on theme: "1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)"— Presentation transcript:

1 1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)

2 2 The representation of numeric data n Denary( 十進制 ) system 265=2 x 10 2 +6 x 10 1 + 5 x 1 n Binary( 二進制 ) system 1100=1 x 2 3 + 1 x 2 2 + 0 x 2 1 + 0 x 2 0 which is equal to 12 in the denary system. 1100 = 12 10

3 3 Octal and Hexadecimal system n Octal system 265 8 = 2 x 8 2 + 6 x 8 1 + 5 x 8 0 = 181 10 n Hexadecimal system 2B5 16 = 2 x 16 2 + 11 x 16 1 + 5 x 16 0 = 693 10

4 4 Numeric system Conversion A. From other systems to denary numbers n 110011 2 = 1 x 2 5 + 1 x 2 4 + 0 x 2 3 + 0 x 2 2 + 1 x 2 1 + 1 x 2 0 = 51 10 n 352 8 = 3 x 8 2 + 5 x 8 1 + 2 x 8 0 = 234 10 n 3E 16 = 3 x 16 1 + 14x 16 0 = 62 10

5 5 Numeric system Conversion B. From the denary system to other systems 254 10 = 3 x 8 2 + 7 x 8 1 + 6 x 8 0 = 376 8 In general, to convert a denary number to other number system with base b, we may use the following algorithm: 1 Divide the denary number by b repeatedly until the quotient is 0. 2 Copy the remainders obtained in reverse order to get the final answer.

6 6 Exercise  Convert 2000 10 into a hexadecimal number.  Answer is 7D0  Convert 51 10 into a binary number.  Answer is 1010001

7 7 From binary to octal system 1 Group the digits of the binary number by three starting form the right. 2 Replace each group of three digits by an equivalent octal digit. Convert 110011 2 into octal number.

8 8 From binary to and hexadecimal system 1 Group the digits of the binary number by four starting form the right. 2 Replace each group of four digits by an equivalent octal digit. Convert 10110101 2 into a hexadecimal number.

9 9 From octal and hexadecimal systems to binary 1 First convert each digit of the octal and hexadecimal number to a group of three and four binary binary digits respectively. 2 Then form the binary number with these groups of binary digits according to the sequence of digits of the original number.

10 10 Example  Convert 3678 into a binary number.  Answer is 11110111  Convert 5C16 into a binary number.  Answer is 101110000010110

11 11 Fixed point representation There are three widely used systems for representing both positive and negative numbers. ! Sign-and-magnitude ! 1’s-complement ! 2’s -complement

12 12 Sign-and-magnitude 1 the leftmost bit (refer to sign bit) is 0 for positive numbers and 1 for negative numbers. 2 The remaining bits represent the binary equivalent of the magnitude (absolute value) of the number.

13 13 Sign-and-magnitude Convert +42 10 and -18 10 to 8-bit binary codes using the sign-and-magnitude representation.

14 14 Example In the sign-and-magnitude system, what is the number represented by the following 8-bit binary codes? 1 00000000 2 10000000 3 11010111

15 15 Two’s complement representation — To obtain the 2’s complement of binary code, the following algorithm may be useful. 1 Obtain the 1’s complement by complementing each bit. That is, change all 0s to 1s to 0s and 1s to 0s. 2 Add 1 to the result binary code.

16 16 Example Find the 2’s complement of the binary code 01001011.

17 17 Two’s complement representation — The following is an algorithm for representing a denary number in the 2’s complement system. 1 Convert the denary number to equivalent binary number. 2 If the denary number is positive, do nothing. Otherwise, obtain the 2’s complement of the binary code.

18 18 Example Represent the number +42 and -18 in 8-bit 2’s complement system.

19 19 Two’s complement representation By reversing the above algorithm, we can convert the 2’s complement representation to denary number. The following is the reversed algorithm. 1 If the leftmost bit is 0, the number is positive. The binary code is the binary equivalent of the number. Convert it to a denary number. 2 If the leftmost bit is 1, the number is negative. Obtain its 2’s complement before converting it to a denary number. The required number is the negative value of the denary number obtained.

20 20 Example What are the denary numbers represented by the following representation in 2’s complement system? 1 01010010 2 10100111

21 21 Two’s complement representation The 2’s complement system is much more common than other systems because of the following: 1 Subtraction can be done by addition. Therefore, no additional circuit is needed. 2 A sign bit and other bits need not be handled separately. 3 There is no distinct +0 and -0 representations as in sign-and-magnitude and 1’s complement systems. 4 One more number, -128, can be represented.

22 22 Overflow — Arithmetic operation may not obtain the correct answer in some cases. This happens when the result is out of range that the binary codes can represent. — For example, when 8-bit binary code is used to represent a number in the 2’s complement system, the range of numbers that can be represented is from -128 to +127. If the result of an operation lies outside this range, overflow occurs.

23 23 Floating-point representation — The fixed point representation is not sufficient for scientific calculations, hence, there is a need to easily accommodate both very large integers and very small fractions. — In this case, the position of the binary point is variable and the binary point is said to float.

24 24 Normalization of binary numbers 0.000111 2 =.111 2 x 2 -3 =.111 2 x 10 -11 -101100 2 = -.1011 2 x 2 6 = -.1011 2 x 10 110

25 25 Representation Suppose 16-bit binary codes is used to represent floating point number. Let us use the leftmost bit to indicate the sign of the number. The next 8 bits to represent the mantissa and the rightmost 7 bits to code the exponent in 2’s complement.

26 26 Example Represent -10.375 10 -1010.011 2 = -.1010011 2 x 2 4 Therefore, the floating representation of - 10.375 is 1101001100000100

27 27 Truncation error In the truncation scheme, any significant bit that cannot be accommodated in the bits for mantissa is ignored. For example, 101100011 is represented by.10110001. 0.000000001 is ignored. This is called a truncation error.

28 28 Rounding error In the rounding scheme, if the bits that cannot be accommodated correspond to a value less than half of the place value of the last bit used to represent mantissa, they are ignored, Otherwise, the place value of the last bit used to represent mantissa is added to the mantissa. For example, the former example 101100011 is represented by.10110010.

29 29 Representation of alphanumeric data and Chinese characters — All letters, digits and symbols in a computer are referred to as alphanumeric characters. — Usually, 8-bit binary is used to code one character. It leads to 2 8 = 256 different characters that can be represented. — The most commonly used coding table follows the standard American Standard Code for Information Interchange, usually referred by its short form ASCII.

30 30 Representation of Chinese characters — Chinese characters are not made up of alphabet. — They need more bits to represent Chinese characters. Indeed, we use 2 bytes, that is 16 bits to represent one single Chinese character. — The most commonly used codes for traditional Chinese characters is the Big5 code and that for simplified Chinese characters is GB codes.

31 31 Parity checking 奇偶檢驗 — Parity checking is a simple method of checking the correctness of received data. — An ASCII code is 8 bits long, but only the rightmost 7 bits are used to represent a character leaving the most significant bit 0. The 8th bit can be used as a parity bit.

32 32 Parity checking 奇偶檢驗 — To maintain even parity 偶數奇偶檢驗, the parity bit is set to 1 if the code being sent has an odd number of 1s. — On the other hand, to maintain odd parity 奇數奇 偶檢驗, the parity bit is set to 1 if the code being sent has an even number of 1s.


Download ppt "1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)"

Similar presentations


Ads by Google