Sie sind auf Seite 1von 3
Hexadecimal system ‘Table 0-1: Base 16 Ni ; Base 16, of the hexadecimal system as itis called in NumiberSystem computer literature, is used as a convenient representation Decimal Binary Hex of binary numbers. For example, it is much easier for a 0. 0000 oO human being to represent a string of Os and 1s such as 1 ‘0001 1 100010010110 as its hexadecimal equivalent of 896H. The 2. 0010 2 binary system has 2 digits, 0 and 1. The base 10 system has 3 oon 3 10 digits, 0 through 9. The hexadecimal (base 16) system 4 0100 4 has 16 digits. In base 16, the first 10 digits, 0 to 9, are the 3. O10L 5 same as in decimal, and for the remaining six digits, the let- 6 O10 6 ters A, B, C, D, E, and F are used. Table 0-1 shows the 7 onl_7 equivalent binary, decimal, and hexadecimal representa- 8 10008 tions for 0 to 15 9 10019 10 1010 A ui lon B To represent a binary number as its equivalent hexa- 12 1100, c decimal number, start from the right and group 4 bits ata 13 NOL D time, replacing each 4-bit binary number with its hex equiv- 4 1110 E alent shown in Table 0-1. To convert from hex to binary, 15 oi Ei each hex digit is replaced with its 4-bit binary equivalent. See Examples 0-4 and 0-5. Example 0-4 Represent binary 100111110101 in hex. Solution: First the number is grouped into sets of 4 bits: 1001 1111 0101. Then each group of 4 bits is replaced with its hex equivalent: 1001 1111 0101 SHEER HAE ‘Therefore, 1001111101012 = 9F5 hexadecimal. [Example 0-5 Convert hex 29B to binary. Solution: Zee aeeeED = 0010 1001 1011 Dropping the leading zeros gives 1010011011 Converting from decimal to hex Converting from decimal to hex could be approached in two ways: 1. Convert to binary first and then convert to hex. Example 0-6 shows this method of converting decimal to hex. 2. Convert directly from decimal to hex by repeated division, keeping track of the remainders. Experimenting with this method is left to the reader. [Example 0-6 (a) Convert 43;9 (0 hex. az 1G ieee) eee deere 1 First, convert to binary. 1 32+84441=45 om 459 = 0010 11012 = 2D hex (b) Convert 62949 to hex. 32 256 1 “8 oa a2 ee eee Ee ee Eee OH LG Ose 629\9~ (512 +64 + 32+ 16 +4 + 1) = 0010 0111 0101, = 275 hex (©) Convert 171449 to hex. 1024 512 256 128 64 32 16 ieee Oa er ° ore on a ie 171449 = (1024 + 512 + 128 + 32 + 16 + 2)=0110 1011 0010, = 6B2 hex Converting from hex to decimal Conversion from hex to decimal can also be approached in two ways: 1. Convert from hex to binary and then to decimal. Example 0-7 demonstrates this method of converting from hex to decimal, 2. Convert directly from hex to decimal by summing the weight of all digits. [Example 0-7 Convert the following hexadecimal numbers to decimal. (a) 6B2;¢ = 0110 1011 0010, 1024 512 256 128 6 32 16 8 ee 1 1 1 0 1 0 1 1 0 0 i 0 1024 + 512 + 128 +32 + 16 +2= 171449 (b) 9F2D jg = 1001 1111 0010 1101) 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8421 1 ON Or a ee ee 0 OO os 32768 + 4096 + 2048 + 1024 + $12 + 256+ 32+8+4+1=40,749;9 CHAPTER 0: INTRODUCTION TO COMPUTING 5 ‘Table 0-2: Counting in Bases_ Counting in bases 10, 2, and 16 Decimal Binary Hex ‘To show the relationship between all ‘000000 three bases, in Table 0-2 we show the sequence (000011 of numbers from 0 to 31 in decimal, along with C001 ae the equiva- Table 0-3: Binary Addition OOOLL 3 lent binary 00100, 4 and hex A+B Carry Sum ool 5 numbers. 940 0. 0 oo110 6 Notice in +1 0 u oon 7 each base 1+0 0 7 (010008 that when L+1 L o ‘10019 one more is 1010 added to oil _-B the highest digit, that digit becomes zero and a 1100 Cc 1 is carried to the next-highest digit position. our D For example, in decimal, 9 + 1 = 0 with a carry 110 to the next-highest position, In binary, 1+ 1 = oun 0 with a carry; similarly, in hex, F + 1 = 0 with 10000 a carry. 10001 ae x 70010 Addition of binary and hex numbers 10011 The addition of binary numbers is a 10100. very straightforward process. Table 0-3 shows Loot the addition of two bits. The discussion of sub- 10110 traction of binary numbers is bypassed since all JOLLL computers use the addition process to imple- 11000 ment subtraction. Although computers have 11001 adder circuitry, there is no separate circuitry for 1010) subtractors. Instead, adders are used in con- M011 junction with 2% complement circuitry to per- 11100 form subtraction. In other words, to implement L101 y", the computer takes the 2°s complement 110 of y and adds it to x. The concept of 2’s com- nn plement is reviewed next. Example 0-8 shows the addition of binary numbers. Example 0-8 Solution: Binary 101 au 1901 10110 ‘Add the following binary numbers. Check against their decimal equivalents. Decimal 1B 22

Das könnte Ihnen auch gefallen