COMS B2 - Intro. To Computer Information Systems Numeral Systems

advertisement
COMS B2 - Intro. To Computer Information Systems
Numeral Systems
The Decimal Numeral System
The numeral system that we most often use is the decimal numeral system. The decimal numeral
system, or base 10, is based upon the use of 10 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9). We are very
used to working with and expressing numbers in the decimal numeral system, so much so that it
becomes difficult to remember that decimal numerals are actually made of digits in appropriate
place values. Recall that the decimal numeral system uses the base (10) raised to the following
powers:
100 (1), 101 (10), 102(100), 103 (1,000), 104(10,000) ...
We take these powers of 10 to create place holders such as the "one's" place, the "ten's" place,
the "hundred's" place, the "thousand's" place, etc. When we express a number such as 235, we
are actually taking the individual digits, placing them in their appropriate place holder,
multiplying the digit by the decimal place value, and then adding the products. Thus, the
decimal numeral 235 could be placed in a decimal place value table:
104
10,000
103
1,000
102
100
2
101
10
3
100
1
5
When we multiply the digits by the decimal place values we get, 2*100 (200), 3*10 (30), and
5*1 (5). Adding the products we get 200+30+5, which equals 235. This process is so ingrained
in us that we usually don't think about it. It is, however, very useful for working with other
numeral systems.
The Binary Numeral System
The binary numeral system works exactly the same as the decimal numeral system, except that
there are only 2 digits (0 and 1) instead of 10. The binary numeral system uses 2 as the base, so
we have the following place values:
20 (1), 21 (2), 22 (4), 23 (8), 24 (16), 25 (32), 26 (64), ...
Instead of the one's place, ten's place, and hundred's place of the decimal numeral system, the
binary numeral system has a one's place, a two's place, a four's place, an eight's place, a sixteen's
place, etc. To convert a binary numeral to a decimal numeral we follow the same basic
procedure as we do in the decimal numeral system:
COMS B2
Numeral Systems
Page 1
COMS B2 - Intro. To Computer Information Systems
1.
2.
3.
Place the binary digits in the chart
Multiply the digit by the place value
Add the multiplied values
To convert the binary numeral 10110 to its decimal equivalent we place the binary digits into the
following place-values chart:
26
64
25
32
24
16
1
23
8
0
22
4
1
21
2
1
20
1
0
We then multiply each digit by its place value:
1*16 = 16, 0*8 = 0, 1*4 = 4, 1*2 = 2, and 0*1 = 0
We then add the products:
16 + 0 + 4 + 2 + 0 = 22
The binary numeral 10110 is equivalent to the decimal numeral 22 (101102 = 2210).
Converting From Decimal to Binary
To convert a decimal numeral to its binary equivalent, we will use the "division remainder"
method. The division remainder method uses the following steps:
1.
2.
3.
4.
Divide the decimal numeral by 2
Place the integer remainder to the side.
Repeat steps 1 and 2, using the quotient from the
previous steps, until the quotient is 0
Place the remainders from left to right going from
bottom to top.
To convert the decimal numeral 23 to its binary equivalent we keep dividing by 2, and writing
the remainders to the side, until the quotient is 0:
2
2
2
2
2
into
into
into
into
into
23 is
11 is
5 is
2 is
1 is
11
5
2
1
0
remainder
remainder
remainder
remainder
remainder
1
1
1
0
1
We then write the remainders from left to right, working from bottom to top. The bottom
remainder (1) becomes the left-most digit, the next-to-bottom remainder (0) is the next digit, the
COMS B2
Numeral Systems
Page 2
COMS B2 - Intro. To Computer Information Systems
third-to bottom remainder (1) is the third digit and so on. We then arrive at the following binary
numeral:
10111
Thus, the binary equivalent of the decimal numeral 23 is 10111 (2310 = 101112). In the above
example, we could have continued even after the quotient became 0. If we did, however, each
subsequent division (2 into 0) would result in 2 remainder 0. Since all those bottom zeroes
would go to the left of the binary numeral, we can ignore them; zeroes on the left of any numeral
can be ignored since they don't change the place values of any other digits.
Following is another example, this time converting decimal 173 to binary:
2
2
2
2
2
2
2
2
into
into
into
into
into
into
into
into
173 is
86 is
43 is
21 is
10 is
5 is
2 is
1 is
86
43
21
10
5
2
1
0
remainder
remainder
remainder
remainder
remainder
remainder
remainder
remainder
1
0
1
1
0
1
0
1
Using the remainders, from bottom to top, as the binary digits we arrive at the following binary
numeral:
10101101
Thus, decimal 173 is equivalent to binary 10101101 (17310 = 101011012).
Addition In Binary
The process of adding two binary numerals is the same as adding two decimal numerals. To add
the two decimal numerals 234 and 675 we add the digits in the corresponding place values. We
begin by adding the 4 and the 5 from the one's places and bring the resulting 9 down. Then we
add the 3 and the 7 in the ten's places and find that the resulting 10 has too many digits, so we
bring only the 0 down and carry the 1 to the top of the next column. We then add the 1 from the
carry to the 2 and the 6 in the hundred's places and bring down the result, 9. The sum of the
decimal numerals 234 and 675 is 909.
1
234
+ 675
909
COMS B2
Numeral Systems
Page 3
COMS B2 - Intro. To Computer Information Systems
Adding two binary numerals is exactly the same, except that there are only two digits in the
binary numeral system ( 0 and 1). Anything greater than 1 requires 2 binary digits and so results
in a carry. As an example we will use the following binary addition problem:
10110
+ 11101
To add the two binary numerals 10110 and 11101 we begin by adding the 0 and the 1 in the
one's places. The result, 1, is placed below in the same column. We then add the 1 and the 0
from the two's places giving the result, 1, in the same column.
10110
+ 11101
11
Next, we add the 1 and the 1 from the four's places, getting two. However, since we are working
in binary, we cannot write 2 in the result (binary digits can only be 0 or 1). Two is written in
binary as 10 (210 = 102). Because 10 is more than one digit, we bring down the right-most digit
(0) and carry the left-most digit (1) to the next place (eight's place).
1
10110
+ 11101
011
We then add the carried 1 to the 0 and 1 in the eight's places. This, again, results in two (binary
10) so we bring down the 0 and carry the one.
11
10110
+ 11101
0011
Finally, we add the carried 1 to the 1 and 1 in the sixteen's places. 1 + 1 + 1 is three, but we
cannot write 3 in a binary numeral; three is written in binary as 11. We bring down the rightmost digit (1) and carry the left-most digit (1) to the next place (sixteen's). Since there is nothing
below it to add to, we can simply bring it down in the sixteen's place:
111
10110
+ 11101
110011
COMS B2
Numeral Systems
Page 4
COMS B2 - Intro. To Computer Information Systems
The Octal Numeral System
The octal numeral system (base 8) is based on the use of 8 digits (0, 1, 2, 3, 4, 5, 6, and 7). Since
8 is two to the third power (8 = 23), each octal digit is exactly equivalent to three binary digits.
Consequently, conversion between binary and octal is quick and easy. To convert octal to
binary, simply replace each octal digit with the equivalent three binary digits. For example, octal
3742 would be converted to binary as follows:
3 = 0112, 7 = 1112, 4 = 1002, 2 = 0102
Thus, Octal 3742 is equivalent to binary 011 111 100 010 (37428 = 0111111000102). To convert
from binary to octal, break the binary numeral into groups of three digits each and convert each
group of three binary digits into one octal digit. For example, we would convert binary
100010111110001 to octal as follows:
100
4
010
2
111
7
110
6
001
1
Thus, binary 100010111110001 is equivalent to octal 42761 (1000101111100012 = 427618).
Octal is often used as a short-hand representation of binary numerals on machines whose word
size is a multiple of three (60, for example).
The Hexadecimal Numeral System
The hexadecimal numeral system (base 16) is based on the use of 16 digits: 0, 1, 2, 3, 4, 5, 6, 7,
8, 9, A, B, C, D, E, and F. The letters A through F are used to represent, in one digit, the values
from 10 through 15: A16 = 10, B16 = 11, C16 = 12, D16 = 13, E16 = 14, and F16 = 15. Since 16 is
two to the fourth power (16 = 24), each hexadecimal digit is equivalent to four binary digits. To
convert hexadecimal to binary, simply rewrite each hex digit as four binary digits. Hexadecimal
3AF4 can be converted to binary as follows:
3 = 00112, A16 = 10 = 10102, F16 = 15 = 11112, 4 = 01002
Thus hexadecimal 3AF4 is equivalent to binary 0011 1010 1111 0100 (3AF416 =
00111010111101002). To convert binary to hexadecimal, break the binary numeral into groups
of four digits and convert each group. We would convert binary 1111010110101110 to
hexadecimal as follows:
1111 0101 1010 1110
1111 = 15 = F16
0101 = 5
1010 = 10 = A16
1110 = 14 = E16
COMS B2
Numeral Systems
Page 5
COMS B2 - Intro. To Computer Information Systems
Thus, the binary numeral 1111010110101110 is equivalent to the hexadecimal numeral F5AE
(11110101101011102 = F5AE16). Hexadecimal is often used as a short-hand representation of
binary numerals on processors that have word sizes evenly divisible by four (8, 16, 32, and 64).
Numeral System Comparison Chart
Decimal
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
COMS B2
Binary
0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111
10000
10001
10010
10011
10100
10101
10110
10111
11000
11001
11010
11011
11100
11101
11110
11111
100000
100001
Octal
0
1
2
3
4
5
6
7
10
11
12
13
14
15
16
17
20
21
22
23
24
25
26
27
30
31
32
33
34
35
36
37
40
41
Numeral Systems
Hex
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
10
11
12
13
14
15
16
17
18
19
1A
1B
1C
1D
1E
1F
20
21
Page 6
Download