Lecture 11: Number Systems
Numeric Data Fixed point Integers (12, 345, 20567 etc) Real fractions (23.45, 23., 0.145 etc.) Floating point such as 23. 45 e 12 Basically an exponent representation
Any number X in fixed point can be represented by a finite sequence of digits X = {x n-1,...x 1, x 0, x -1, x -m }, where, 0 x i < r and -m i n-1 We can compute decimal value of X as follows: V(X) = x i * r i { -m i n-1} OR V(X) = x i * r i {0 i n-1} + x j * r j { -m j -1} integral part fractional part Here r is base (radix) and V(X) is decimal value of X.
Number Systems System Base Digits Examples Decimal 10 0-9 234, 15.23 Binary 2 0 & 1 110101 11011.101 Octal 8 0 7 123, 23.10 Hexadecimal 16 0 9, A,B,C,D,E,F 1AF2, F23.AA
Binary Number System Most modern computer systems operate using binary logic. The computer represents values using two voltage levels (usually 0V for logic 0 and higher V for logic 1). With two levels we can represent exactly two different values. These could be any two different values, but by convention we use the values zero and one. These two values, coincidentally, correspond to the two digits used by the binary number system.
The weighted values for each position is determined as follows: 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 2-1 2-2 128 64 32 16 8 4 2 1 0.5 0.25 Leftmost digit is most significant digit (MSD) whereas rightmost digit is least significant digit (LSD)
Number Base Conversion Binary to Decimal It is very easy to convert from a binary number to a decimal number. Multiply each digit by its weighted position, and add each of the weighted values together. For example, the binary value 11001010 represents: (11001010)b = 1*2 7 +1*2 6 +0*2 5 +0*2 4 +1*2 3 +0*2 2 +1*2 1 + 0*2 = 1*128+1*64+0*32+0*16+1*8+0*4 +1*2+0*1 = 128 + 64 + 0 + 0 + 8 + 0 + 2 + 0 = 202
Decimal to Binary Decimal to binary conversion is slightly more difficult. Repeated Division By 2 divide the decimal number by 2 Remainder is the LSD Quotient becomes new number. This process is continued by dividing the new number by 2 and storing the remainder until the quotient is 0. The remainders are written beginning at the least significant digit (right) and each new digit is written to more significant digit (the left) of the previous digit.
Consider the conversion of 166 to binary number Division Quot Rem Binary Number 166/2 83 0 0 83/2 41 1 10 41/2 20 1 110 20/2 10 0 0110 10/2 5 0 00110 5/2 2 1 100110 2/2 1 0 0100110 1/2 0 1 10100110
Decimal Fraction to Binary fraction Fraction (0.125) 10 = (0.001) b. Use the following method. Repeat the following until fraction becomes 0 or the number of digits have sufficient accuracy. Multiply a decimal fraction by 2. Separate integral and fractional part. new decimal fraction is fractional part obtained above.
Fraction Integral Part New fraction 0.125 * 2 0 0.250 0.250 * 2 0 0.500 0.500 * 2 1 0.000 Collect the integral part as follows: (0.125) 10 = (0.001) 2
Octal Number System Although this was once a popular number base, especially in the Digital Equipment Corporation PDP/8 and other old computer systems, it is rarely used today. The Octal system is based on the binary system with a 3-bit boundary. The Octal Number System: uses base 8 includes only the digits 0 through 7 (any other digit would make the number an invalid octal number) The weighted values for each position is as follows:
The weighted values for each position is determined as follows: 8 5 8 4 8 3 8 2 8 1 8 0 32768 4096 512 64 8 1
Binary to Octal Conversion It is easy to convert from an integer binary number to octal. This is accomplished by: Break the binary number into 3-bit sections from the LSB to the MSB. Convert the 3-bit binary number to its octal equivalent.
For example, the binary value (1010111110110010) 2 will be written: 001 010 111 110 110 010 1 2 7 6 6 2 Corresponding octal number is: (127662) q The base q represent Octal base.
Octal to Binary Conversion It is also easy to convert from an integer octal number to binary number. This is done as follows: Convert the decimal number to its 3-bit binary equivalent. Combine the 3-bit sections by removing the spaces.
For example, the octal value (127662) q will be written : 1 2 7 6 6 2 001 010 111 110 110 010 Corresponding binary number is: (1010111110110010) 2
Octal to Decimal Conversion To convert from Octal to Decimal, multiply the value in each position by its Octal weight and add each value. Using the value from the previous example, (127662) q, we would expect to obtain the decimal value (44978) 10.
Conversion of (127662) q to decimal number 1*8 5 2*8 4 7*8 3 6*8 2 6*8 1 2*8 0 1* 32768 2* 4096 7*512 6*64 6*8 2*1 32768 8192 3584 384 48 2 = 32768 + 8192+ 3584 + 384 +48 + 2 = (44978) 10
Decimal to Octal Conversion To convert decimal to octal is similar to the one done for Decimal to binary. Here repeated division is done by 8. Repeated Division By 8 Divide the decimal number by 8, and write the remainder on the side as the least significant digit. This process is continued by dividing the quotient by 8 and writing the remainder until the quotient is 0.
When performing the division, the remainders which will represent the octal equivalent of the decimal number are written beginning at the LSD (right) and each new digit is written to the next more significant digit (the left) of the previous digit. Consider decimal number (166) 10. Convert to its equivalent Octal number.
Division Quot Rem Octal Number 166/8 20 6 6 20/8 2 4 46 2/8 0 2 246 Therefore, (166) 10 = (246) 8 or (246) q
Hexadecimal Number System The Hexadecimal Number System: uses base 16 includes only the digits 0 through 9 and the letters A, B, C, D, E, and F Hexadecimal numbers offer the two features: hex numbers are very compact it is easy to convert from hex to binary and binary to hex. The Hexadecimal system is based on the binary system using 4-bit (a Nibble) boundary. In the Hexadecimal number system, the hex values greater than 9 carry the following decimal value:
Binary (b) Decimal Hex(h) (0000) b (0) 10 (0) h (0001) b (1) 10 (1) h (0010) b (2) 10 (2) h (0011) b (3) 10 (3) h (0100) b (4) 10 (4) h (0101) b (5) 10 (5) h (0110) b (6) 10 (6) h (0111) b (7) 10 (7) h (1000) b (8) 10 (8) h (1001) b (9) 10 (9) h
Binary (b) Decimal Hex(h) (1010) b (10) 10 (A) h (1011) b (11) 10 (B) h (1100) b (12) 10 (C) h (1101) b (13) 10 (D) h (1110) b (14) 10 (E) h (1111) b (15) 10 (F) h
Hexadecimal to Binary Conversion simply brake the binary number into 4-bit groups beginning with the LSB and substitute the corresponding four bits in binary for each hexadecimal digit in the number. For example, to convert (ABCD) h into a binary value, simply convert each hexadecimal digit according to the table above. The binary equivalent is: (ABCD) h = (1010 1011 1100 1101) 2
Binary to Hex Conversion It is easy to convert from an integer binary number to hex. This is accomplished by: Break the binary number into 4-bit sections from the LSB to the MSB. Pad the binary number with leading zeros if needed. Convert the 4-bit binary number to its Hex equivalent. For example, the binary value (110111110110010) 2 will be written: (011 0 1111 1011 0010) 2 = (6FB2) h
Hex Decimal Conversion Hex to Decimal conversion Multiply the value in each position by its hex weight and add each value. We would expect to obtain the decimal value (44978) 10 corresponding to (AFB2) h. A*16 3 + F*16 2 + B*16 1 + 2*16 0 = 10*4096 +15*256 +11*16 + 2*1 = 40960 + 3840 + 176 + 2 = (44978) 10 Decimal to Hex Conversion The typical method to convert from decimal to hex is repeated division by 16 (similar to other bases).
Base (r) Decimal Conversion Base r to Decimal Assume {x n-1,...x 1, x 0, x -1, x -m } in base r, X = + x 2 * r 2 + x 1 * r 1 + x 0 * r 0 + x -1 * r -1 + Decimal to Base r Repeated Division By r Write the remainder on the side as the LSD. This process is continued by dividing the quotient by r and writing the remainder until the quotient is 0.