Computer Fundamentals Lecture 2: Number Systems
03/12/09
Sri Lanka Institute of Information Technology
1
Objectives After
completing this lecture you will be able to: Explain different positionally-waited number systems Translate numbers between number systems Appraise binary number system
03/12/09
Sri Lanka Institute of Information Technology
2
Agenda Number
bases used with computers Why binary? Number Base Conversion Conversion of Fractions
03/12/09
Sri Lanka Institute of Information Technology
3
Number bases used with computers
Decimal, b=10 a={0,1,2,3,4,5,6,7,8,9}
Binary, b=2 a={0,1}
Octal, b=8 a={0,1,2,3,4,5,6,7}
Hexadecimal, b=16 a={0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
03/12/09
Sri Lanka Institute of Information Technology
4
Why Binary is used in Computers?
Electronic components that represent binary are better than those that represent binary because of;
03/12/09
Easier to design Cost effective
Sri Lanka Institute of Information Technology
5
Number Base Conversion Decimal to Binary
divide the number successively by 2, and after each division record the remainder which is either 1 or 0. example, 12310 becomes 123/2 =61 r=1 61/2 = 30 r=1 30/2 = 15 r=0 15/2 = 7 r=1 7/2 =3 r=1 3/2 =1 r=1 1/2 =0 r=1 12310 = 11110112
03/12/09
Sri Lanka Institute of Information Technology
6
Number Base Conversion Decimal to Octal
Divide the number by 8 remainder is a number in the range 0 to 7. example, 462910 becomes 4629/8= 578 r=5 578/8= 72 r=2 72/8= 9 r=0 9/8 =1 r=1 1/8 =0 r=1 462910 =110258
03/12/09
Sri Lanka Institute of Information Technology
7
Number Base Conversion Decimal to Hexadecimal
Divide the number by 16 remainder lies in the decimal range 0 to 15, corresponding to the hexadecimal range 0 to F. example, 5324110 becomes 53241/16 = 3327 r=9 3327/16 = 207 r=15 = F 207/16 =12 r=15 = F 12/16 =0 r=12 = C 5324110=CFF916
03/12/09
Sri Lanka Institute of Information Technology
8
Number Base Conversion Binary to Decimal
03/12/09
Take the left most none zero bit, double it and add it to the bit on its right. Now take this result, double it and add it to the next bit on the right. Continue in this way until the least significant bit has been added in.
Sri Lanka Institute of Information Technology
9
Number Base Conversion Binary to Decimal (cont’d) For example, 10101112 becomes
Therefore, 10101112 = 8710 03/12/09
Sri Lanka Institute of Information Technology
10
Number Base Conversion Binary to Octal
Form the bits into groups of three starting at the binary point and moving leftwards. Replace each group of three bits with the corresponding octal digit (0 to 7). For example, 110010111012 becomes 11 001 011 101 3
1
3
5
Therefore,110010111012 = 31358 03/12/09
Sri Lanka Institute of Information Technology
11
Number Base Conversion Binary to Hexadecimal
The binary number is formed into groups of four bits starting at the decimal point. Each group is replaced by a hexadecimal digit from 0 to 9, A, B, C, D, E, and F. For example, 110010111012 becomes 110 0101 1101 6 5 D Therefore, 110010111012 = 65D16
03/12/09
Sri Lanka Institute of Information Technology
12
Number Base Conversion Octal to Binary
Each octal digit is simply replaced by its 3-bit binary equivalent. It is important to remember that (say) 3 must be replaced by 011 and not 11. For example, 413578 becomes 4 1 3 5 7 100 001 011 101 111 Therefore,413578 = 1000010111011112.
03/12/09
Sri Lanka Institute of Information Technology
13
Number Base Conversion Hexadecimal to Binary
Each hexadecimal digit is replaced by its 4-bit binary equivalent. For example AB4C16 becomes
A
1010
B
1011
4
0100
C
1100
Therefore, AB4C16 = 10101011010011002
03/12/09
Sri Lanka Institute of Information Technology
14
Number Base Conversion Octal to Decimal
Take the left-most digit, Multiply it by eight and add it to the digit on its right. Then, multiply this subtotal by eight and add it to the next digit on its right. The process ends when the left-most digit has been added to the subtotal. For example, 64378 becomes 6 4 3 7 48 52 416 419 3352 3359 Therefore, 64378 = 335910
03/12/09
Sri Lanka Institute of Information Technology
15
Number Base Conversion Hexadecimal to Decimal
The method is identical to the procedures for binary and octal except that 16 is used as a multiplier.
For example, 1AC16 becomes
1
A
C
16 26 416 428 Therefore, 1AC16
03/12/09
=
42810
Sri Lanka Institute of Information Technology
16
Conversion of Fractions Converting Binary Fractions to Decimal Fractions
For example, consider the conversion of 0.011012 into decimal form. 0.0 0 1 1 0 1 1/2
13/16 13/16
5/8 13/8
1/4 5/4
1/2
13/32 Therefore, 0.011012 = 13/32.
03/12/09
Sri Lanka Institute of Information Technology
17
Conversion of Fractions Converting Decimal Fractions to Binary Fractions
For example, 0.687510 becomes
0.6875 0.3750 0.7500 0.5000
x x x x
2 2 2 2
1.3750 0.7500 1.5000 1.0000
0.0000 x 2 ends the process Therefore, 0.687510 = 0.10112
03/12/09
Sri Lanka Institute of Information Technology
18
Thank You Lecture 03: Computer Arithmetic
03/12/09
Sri Lanka Institute of Information Technology
19