The Number Systems : The Number Systems Introduction to Computer – COMP 201 Ms. Jean Penaflorida, MSc.IT
Dilla University Chapter 3
Agenda : 2 Agenda Positional Number Systems
Different number systems
Conversion of one number system to another
Fractional numbers
Computer Arithmetic
Computer Codes
Introduction : 3 Introduction Every computers stores numbers, letters, and other special characters in coded form.
Number system are basically of two types: Non-positional and positional.
Non-positional number – such as I, II, III, IV, V,… so on.
Each symbol represent the same value, regardless of its position in the number, and symbols are simply added to find out the value of particular number.
Positional Number Systems : 4 Positional Number Systems There are only few symbols called digits.
The value of each digit in such number is determined by three considerations:
The digit itself
The position of the digit in the number
The base of the number system (where base is defined as the total number of digits available in the number system.)
It is called Decimal number system.
Positional Number Systems : 5 Positional Number Systems Sample:
2586 = (2X1000) + (5X100) + (8X10) + (6X1)
OR
In 258610 the digit 6 signifies 6 X 100 = 6
In 258610 the digit 8 signifies 8 X 101 = 80
In 258610 the digit 5 signifies 5 X102 = 500
In 258610 the digit 2 signifies 2 X 103 = 2000
Different Number Systems : 6 Different Number Systems Decimal Number System – with the base of 10 and symbol used are 0,1, 2……..9
Binary Number System – with the base of 2 and symbol used are 1 & 0.
Octal Number System – with the base of 8 and symbol used are 0,1,… 7
Hexadecimal Number System – with the base of 16 and symbol used are 0, 1,….9, A, B,… F representing the decimal values 10, 11,….15.
Conversion : 7 Conversion Decimal to Binary:
Sample
470610 = ? 2
10010011000102
More sample
169410 = ?2
13510 = ?2
Conversion : 8 Conversion Decimal to Octal number
Sample:
250210 = ?8
47068
More sample:
56210 = ?8
261410 = ?8
Conversion : 9 Conversion Decimal to Hexadecimal
Sample:
42810 = ?16
1AC16
More sample:
257310 = ?16
456310 =?16
Conversion : 10 Conversion Binary to Decimal
Sample:
110012 = ?10
2510 1 X 24 + 1 X23 + 0 X22 + 0 X 21 + 1 X 20 16 + 8 + 0 + 0 + 1 = 25 More sample:
1111012 = ?10
101010102 = ?10
Conversion : 11 Conversion Octal to Decimal
Sample:
5628 = ?10 5 x 82 + 6 X 81 + 2 X 80 320 + 48 + 2 = 37010 More sample:
7628 = ?10
51278 = ?10
Conversion : 12 Conversion Hexadecimal to Decimal
Sample:
2A3B16 = ?10 2 x 163 + (A=10) x 162 + 3 X 16 1 + (B=11) x160 8192 + 2560 + 48 + 11 = 1081110 More sample:
A2BD416 =?10
CFFE216 = ?10
Conversion : 13 Conversion Binary to Octal
Sample:
1011102 = ?8
568 101 110 5 6
Conversion : 14 Conversion Octal to Binary
Sample:
5628 = ?2
101 110 0102 5 8= 1012
68 = 1102
28 = 0102
Conversion : 15 Conversion Binary to Hexadecimal
Sample:
110100112 = ?16
D316
Sample
1110001102 = ?16
1D316 1101 0011 D 3 0001 1100 0110 1 D 3
Conversion : 16 Conversion Hexadecimal to Binary
Sample:
2AB16 = ?2
0010101010112 216 = 00102
A16 = 10102
B16 = 10112
Fractional Numbers : 17 Fractional Numbers The same general way in the decimal number.
0.235 = (2X10-1) + (3X10-2 )+ (5X10-3)
68.53 = (6X101) + (8X100) + (5X10-1) + (3X10-2) Position 4 3 2 1 0 . -1 -2 -3 -4
Position Value 24 23 22 21 20 . 2-1 2-2 2-3 2-4
Quantity
Represented 16 8 4 2 1 . ½ ¼ 1/8 1/16
Fractional Numbers : 18 Fractional Numbers Sample:
Find the decimal equivalent of the binary number 110.1012.
Solution:
6.62510 110.1012 = 1 x 22 + 1 x 21 + 0 x 20 + 1 x 2-1 + 0 x 2-2 + 1 x 2-3
= 4 + 2 + 0 + 0.5 + 0 + 0.125
= 6 + 0.5 + 0.125
= 6.62510
Fractional Numbers : 19 Fractional Numbers Sample:
Find the decimal equivalent of the hexadecimal number 2B.C416.
Solution:
43.76565210 2B.C416 = 2x161 + Bx160 + cx16-1 + 4x16-2
= 32 + 11 + 12/16 + 4/256
= 43 + 0.75 + 0.015625
= 43. 76565210
Fractional Numbers : 20 Fractional Numbers Sample:
Find the decimal equivalent of the octal number 127.548.
Solution:
87.687510 127.548 = 1x82 + 2x81 + 7x80 + 5x8-1 + 4x8-2
= 64 + 16 + 7 + 5/8 + 4/64
= 87 + 0.625 + 0.0625
= 87. 687510
Fractional Numbers : 21 Fractional Numbers Converting fractional numbers to binary.
Sample:
0.25610 = ?2
0.0100000112 0.256 x 2 = 0.512 0
0.512 x 2 = 1.024 1
0.024 x 2 = 0.048 0
0.048 x 2 = 0.096 0
0.096 x 2 = 0.192 0
0.192 x 2 = 0.384 0
0.384 x 2 = 0.768 0
0.768 x 2 = 1.536 1
0.536 x 2 = 1.072 1
0.072 x 2 = 0.144 0
0.144 x 2 = 0.288 0
0.288 x 2 = 0.576 0
Computer Arithmetic : Computer Arithmetic Chapter 3 – Number Systems
Computer Arithmetic : 23 Computer Arithmetic Binary Addition
Is performed in the same manner as in decimal arithmetic.
Since 1 is the largest digit in the binary number system, any sum greater than 1 requires a digit to be carried over.
Computer Arithmetic : 24 Computer Arithmetic Sample:
101 + 10
10011 + 1001 101
+ 10
111 Binary 5
+ 2
7 Decimal carry - 1 1
10011
+ 1001
11100 1
19
+ 9
28
Computer Arithmetic : 25 Computer Arithmetic Binary Subtraction – is applied to subtraction of numbers in other number systems.
Determine if it is necessary to borrow.
If the subtrahend (the lower digit) is larger than the minuend (the upper digit), it is necessary to borrow form the column to the left.
It is important to note here that the value borrowed depends upon the base of the number system.
Simply to subtract lower value from the upper value.
Slide 26: 26 Binary Subtraction
Sample:
Subtract 011102 from 101012
Answer - 001112 12
0202
10101
-01110
00111
Computer Arithmetic : 27 Computer Arithmetic Additive Method of subtraction – is know as complementary subtraction.
Complement subtractions:
For a number which has n digits in it, a complementary is defined as the difference between the number and the based raised to the nth power minus one.
Computer Arithmetic : 28 Computer Arithmetic Sample:
Find the complement of 3710. Solution:
Since the number has 2 digits, and the value of base is 10.
(Base)n – 1 = 102 – 1 = 99
Now, 99 – 37 = 62
Hence, the complement of 3710 = 6210 Sample:
Find the complement of 101012. Solution:
Since the number has 5 digits, and the value of base is 2.
(Base)n – 1 = 25 – 1 = 3110
Also, 101012 = 2110
Now, 3110 – 2110 = 1010 - 10102
Hence, the complement of 101012 = 010102
Computer Arithmetic : 29 Computer Arithmetic Subtraction by the complementary method involves the following steps:
Find the complement of the number you are subtracting (subtrahend)
Add this to the number form which you are taking away (minuend)
If there is a carry 1, add it to obtain the result; if there is no carry, recomplement the sum and attach a negative sign to obtain the result.
Computer Arithmetic : 30 Computer Arithmetic Sample:
Subtract 5610 from 9210 using complementary method.
Solution:
Slide 31: 31 Binary Multiplication – also follows the same general rules as multiplication in decimal number system.
Computer Arithmetic : 32 Computer Arithmetic Sample:
Multiply the binary numbers 1010 and 1001
Computer Arithmetic : 33 Computer Arithmetic Binary Division – it is similar to decimal division. The rules for binary division are:
Start from the left of the dividend
Perform a series of subtractions, in which the divisor is subtracted form the dividend.
If subtraction is possible, put a 1 in the quotient and subtract the divisor form the corresponding digits of dividend.
If subtraction is not possible (divisor greater than remainder), record a 0 in the quotient.
Bring down the next digit to add to the remainder digits. Proceed as before in a manner similar to long division.
Computer Arithmetic : 34 Computer Arithmetic Sample:
Divide binary 100001 by 110.
Sample Problems: : Sample Problems: Add the binary numbers 1010110 and 1011010
Subtract 0110111 from 1101110
Multiply 1100 and 1010
Divide 11001 by 101
Find the complement of the following:
101101
001101001110
10110001 35
Computer Codes : 36 Computer Codes BCD Code – Binary Coded Decimal
EBCDIC – Extended Binary-Coded Decimal Interchange Code.
ASCII – American Standard Code for Information Interchange.
BCD Code : 37 BCD Code BCD equivalent of decimal digits.
Sample:
4210 = ? In BCD 4210 = 0100 0010
4 2 or 01000010 in BCD
BCD Code : 38 BCD Code
BCD Code : 39 BCD Code
BCD Code : 40 BCD Code
BCD Code : 41 BCD Code
EBCDIC Code : 42 EBCDIC Code The BCD code was extended from 6-bit to 8-bit code.
The added 2 bits are used as additional zone bits, expanding the zone to 4 bits.
The resulting code is called EBCDIC.
It is possible to represent 256 (28) different characters, instead of 64 (26).
The control characters are used to control such activities as printer vertical spacing, movement of cursor on the terminal screen, etc.
All of the 256 bit combinations have not yet been assigned characters.
EBCDIC Code : 43 EBCDIC Code
EBCDIC Code : 44 EBCDIC Code
EBCDIC Code : 45 EBCDIC Code
EBCDIC Code : 46 EBCDIC Code
EBCDIC Code : 47 EBCDIC Code
EBCDIC Code : 48 EBCDIC Code Sample:
Using Binary notation, write the EBCDIC coding for the word BIT. How many bytes are required for this representation?
Solution: B = 1100 0010 in EBCDIC binary notation
I = 1100 1001 in EBCDIC binary notation
T = 1110 0011 in EBCDIC binary notation 11000010 11001001 11100011
B I T 3 bytes will be required for this representation, because each letter requires 1 byte (or 8 bits)
EBCDIC Code : 49 EBCDIC Code Sample:
Write the EBCDIC zoned-decimal coding for the value +256 (use hexadecimal). How many bytes will be required for this representation?
Solution: +256 = F2F5C6 in EBCDIC
Each hexadecimal digit requires 4 bits, and there are altogether 6 hexadecimal digits. Therefore, 6 X 4 = 24 bits or 3 bytes (8 bits – 1 byte) will required for this representation.
ASCII Code : 50 ASCII Code ASCII is of two types – ASCII-7 and ASCII-8.
ASCII-7 is a 7-bit code, which allows 128 (27) different characters.
The first 3-bits are used as zone bits, and the last 4 bits indicate the digit.
ASCII-8 is an extended version of ASCII-7.
It is an 8-bit code, which allows 256 (28) different characters, rather than 128.
ASCII-7 Code : 51 ASCII-7 Code
ASCII-7 Code : 52 ASCII-7 Code
ASCII-7 Code : 53 ASCII-7 Code
ASCII-8 Code : 54 ASCII-8 Code
ASCII-8 Code : 55 ASCII-8 Code
ASCII-8 Code : 56 ASCII-8 Code
ASCII Code : 57 ASCII Code Sample:
Write the binary coding for the word BOY in ASCII-7. How many bytes are required for this representation?
Write the binary coding for the word SKY in ASCII-8. How many bytes are required for this representation?
Write the hexadecimal coding for the word GIRL in ASCII-7. How many bytes are required for this representation?
ASCII Code : 58 ASCII Code Solution:
B = 1000010 in ASCII-7 binary notation
O = 1001111 in ASCII-7 binary notation
Y = 1011001 in ASCII-7 binary notation 1000010 1001111 1011001
B O Y Since each character in ASCII-7 requires one byte for its representation, and there are 3 characters in the word BOY, 3 bytes will be required for this representation.
ASCII Code : 59 ASCII Code Solution:
S = 10110011 in ASCII-8 binary notation
K = 10101011 in ASCII-8 binary notation
Y = 10111001 in ASCII-8 binary notation 10110011 10101011 10111001
S K Y Since each character in ASCII-8 requires one byte for its representation, and there are 3 characters in the word SKY, 3 bytes will be required for this representation.
ASCII Code : 60 ASCII Code Solution:
G = 47 in ASCII-7 hexadecimal notation
I = 49 in ASCII-7 hexadecimal notation
R = 52 in ASCII-7 hexadecimal notation
L = 4C in ASCII-7 hexadecimal notation 47 49 52 4C
G I R L Since each character in ASCII-7 requires one byte for its representation, and there are 4 characters in the word GIRL, 4 bytes will be required for this representation.
End of the session…. : End of the session…. Do you have Questions?