unit1: computernumber system - mobin...
TRANSCRIPT
Page 1 of 35 Mobin
UNIT1: COMPUTERNUMBER SYSTEM
Binary ,Decimal , Octal and Hexadecimal Number-Base Conversions Addition, Subtraction and Multiplication of Computer Number System Compliment (1’s , 2's and r’s complement) Signed Binary Number Binary Arithmetic
Page 2 of 35 Mobin
COMPUTER NUMBER SYSTEM
1.1Binary ,Decimal , Octal and Hexadecimal
1. Introduction of Computer Number System:We used the man in the long history of different numerical systems and our systemwe call the decimal system.
Numerical system
1. Binary (0,1)2 2. Decimal (0,to 91)10 3. Octal(0 to 7)8 4. Hexadecimal(0 to 9 ABCDEF)2
Binary System : الثنائي النظام
This means that the code contains only the digits 0 and 1 and uses this code toconvert any data to write the number 1 and 0.
Decimal System النظام العشريThe decimal system, if the basis of (10) and the following figures by category(0,1,2,3,4,5,6,7,8,9)
Octal System النظـــــــــام الثماني
Octal number system is a counting system with a basis of the number 8, and usesthe numbers from 0 to 7.
Hexadecimal Systemسداسي عشري
A Hexadecimal Number is based on the number 16As well as the familiar digits 0 to 9, there are also the letters "A","B","C","D","E"and "F" in place of the decimal numbers 10 to 15.
Page 3 of 35 Mobin
1.2Number-Base Conversions
Q1. Convert Binary to Decimal Number Systems?
(1010111)2 = (--------)10
Ans: 64 32x 16 8x 4 2 1
1 0 1 0 1 1 1
64+ 16+4+2+1= 87
(1010111)2 = (87)10
Q2. Convert Decimal to Binary Number System
(274)10 = (----------------)2
Ans:
256 128x 64x 32x 16 8x 4x 2 1x
1 0 0 0 1 0 0 1 0
256 + 16 + 2 = 274
(274)10 = (100010010)2
Q3. Convert Binary to Octal Number Systems?
(1100110)2 = (---------)8
Ans: Add leading zeros0 0 1 1 0 0 1 1 0
1 4 6
(1100110)2 = (146)8
Page 4 of 35 Mobin
Q4 Convert Octal to Binary Number Systems?
(6132)8 = (------------)2
Ans: إجابة
6 = 110 1 = 001 3 = 011 2 = 010
(110 001 011 010)2
(6132)8 = (110 001 011 010)2
Q5. Convert Binary to Hexadecimal number systems?
(1010110)2 =(------)16
Ans: 1010110
0 101 0 1 1 0
5 6
(1010110)2 =(56)16
Q6 Convert Hexadecimal to Binary number systems?
(39F)16 = (-----------)2.
Ans: 3 = 0011 9 = 1001 F = 1111
(39F)16 = (001110011111)2
Page 5 of 35 Mobin
Page 6 of 35 Mobin
2. Binary Arithmeticثنائیالحساب
Binary arithmetic is essential part of all the digital computers and many otherdigital system.
2.1 Binary Addition الثنائیةزائد
It is a key for binary subtraction, multiplication, division. There four rules of thebinary addition.
In fourth case, a binary addition is creating a sum of (1+1=10) i.e. 0 is write in thegiven column and a carry of 1 over to the next column.
EXAMPLE - ADDITION
2.2Binary Subtractionالثنائیة ناقصSubtraction and Borrow, these two words will be used very frequently for thebinary subtraction.There four rules of the binary substration.There four rules of thebinary Subtraction.
Page 7 of 35 Mobin
EXAMPLE - SUBTRACTION
2.3 Binary Multiplicationالثنائیةضرب
Binary multiplication is similar to decimal multiplication. It is simpler thandecimal multiplication because only 0s and 1s are involved.There four rules of thebinary multiplication.
EXAMPLE - MULTIPLICATION
Page 8 of 35 Mobin
2.4 Binary Division
Binary division is similar to decimal division. It is called as the long divisionprocedure.
EXAMPLE - DIVISION
3. Octal Arithmetic
Octal Number System
Following are the characteristics of an octal number system.
Uses eight digits, 0,1,2,3,4,5,6,7.
Also called base 8 number system Each position in a octal number represents a 0 power of the base (8). Example 80
Last position in a octal number represents a x power of the base (8). Example8x where x represents the last position - 1.
Page 9 of 35 Mobin
EXAMPLE
Octal Number: 125708
Calculating Decimal Equivalent:
StepOctalNumber
Decimal Number
Step 1 125708((1 x 84) + (2 x 83) + (5 x 82) + (7 x 81) +(0 x 80))10
Step 2 125708 (4096 + 1024 + 320 + 56 + 0)10
Step 3 125708 549610
Note: 125708 is normally written as 12570.
3.1 Octal Addition
Page 10 of 35 Mobin
3.2 Octal Subtraction
3.2 Octal Multiplication
Page 11 of 35 Mobin
4. Hexadecimal Arithmetic
Hexadecimal Number System
Following are the characteristics of a hexadecimal number system.
Uses 10 digits and 6 letters, 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
Letters represents numbers starting from 10. A = 10. B = 11, C = 12, D = 13, E =14, F = 15.
Also called base 16 number system
Each position in a hexadecimal number represents a 0 power of the base (16).Example 160
Last position in a hexadecimal number represents a x power of the base (16).Example 16xwhere x represents the last position - 1.
EXAMPLE
Hexadecimal Number: 19FDE16
Calculating Decimal Equivalent:
Step Hexadecimal Number Decimal Number
Step 1 19FDE16((1 x 164) + (9 x 163) + (F x162) + (D x 161) + (E x 160))10
Step 2 19FDE16((1 x 164) + (9 x 163) + (15 x162) + (13 x 161) + (14 x 160))10
Step 3 19FDE16(65536+ 36864 + 3840 + 208 +14)10
Step 4 19FDE16 10646210
Note: 19FDE16 is normally written as 19FDE.
Page 12 of 35 Mobin
4.1 Hexadecimal Addition
Page 13 of 35 Mobin
4.2 Hexadecimal Subtraction and Multiplication
Page 14 of 35 Mobin
1.3 Complement Arithmeticتكماللحساب
Complements are used in the digital computers in order to simplify the subtractionoperation and for the logical manipulations. For each radix-r system (radix rrepresent base of number system) there are two types of complements
S.N. Complement Description
1 Radix ComplementThe radix complement is referred to as ther's complement
1Diminished RadixComplement
The diminished radix complement isreferred to as the (r-1)'s complement
Binary system complements
As the binary system has base r = 2. So the two types of complements for thebinary system are 2's complement and 1's complement.
1's complement
The 1's complement of a number is found by changing all 1's to 0's and all 0's to1's. This is called as taking complement or 1's complement. Example of 1'sComplement is as follows.
Page 15 of 35 Mobin
2's complement
The 2's complement of binary number is obtained by adding 1 to the LeastSignificant Bit (LSB) of 1's complement of the number.
2's complement = 1's complement + 1
Example of 2's Complement is as follows.
Page 16 of 35 Mobin
Page 17 of 35 Mobin
Page 18 of 35 MobinPage 18 of 35 MobinPage 18 of 35 Mobin
Page 19 of 35 Mobin
Page 20 of 35 Mobin
Page 21 of 35 MobinPage 21 of 35 MobinPage 21 of 35 Mobin
Page 22 of 35 Mobin
R’s AND (R-1)’s COMPLEMENT OF NUMBER SYSTEMS
In digital system complement is used to find subtraction of number base systemand for digital manipulation. If R be the base of a number system then that numbersystem can have two complements respectively R’s and (R-1)’s complement. Thebase of binary number system is 2 so there can be 2’s complement and 1’scomplement of this system. Similarly in hexadecimal number system there are 15’scomplement and 16’s complement. Now the general formula for find R’scomplement and (R-1)’s are given below:
R’s complement of any number system = (Rn)10-N and(R-1)’s complement of any number system = {(Rn)10-1)}-NWhere R = Radix or base of that number system
n = Number of digits in the number andN = The given number
R’s AND (R-1)’s COMPLEMENT OF BINARY NUMBER SYSTEM
The base of binary number system is 2 so for binary number R=2 and R-1 = 1 thus1’s complement for binary numbers is {(2n)10-1)}-N and2’s complement is (2n)10-N.Example: Find 1’s complement and 2’s complement of the binary number10110012?Solution: 1’s complement of 1011001= {(27)10-1)} – 10110012
= 12710– 10110012
= 11111112– 10110012
= 01001102
2’s complement of 1011001= (27)10-N= 12810– 10110012
= 100000002– 10110012
= 01001112
Page 23 of 35 Mobin
There is a short cut method for finding 1’s complement and 2’s complement ofbinary numbers. We just need to alter 0’s by 1’s and 1’s by 0’s for 1’s complementand for 2’s complement find 1’s complement from this method then add 1 toLSB(least significant bit). So the above problem can be solved as:1’s complement of 10110012
= 01001102
2’s complement of 10110012
= 1’s complement of the binary number + 1=01001102+1= 01001112
R’s AND (R-1)’s COMPLEMENT OF BASE 3 NUMBER SYSTEM
Here the base is 3 so R = 3 and R-1 = 2 thus 3’s complement of base 3 numbersystem = (3n)10-N and 2’s complement of base 3 number system = {(3n)10-1)}-N.Example: Find 3’s complement and 2’s complement of 1213?Solution: 3’s complement and 2’s complement is found as:2’s complement of 1213
= {(33)10-1)} – 1213
= 2610– 1610
= 1010
= 1013
3’s complement of 1213
= (3n)10-N= 2710– 163
= 1110
= 1023
There is a shortcut method for finding 2’s and 3’s complement of this number basesystem. Subtract each digit of the given number from 2 and take them together.Thus the value obtained is the 2’s complement of the given number. And for 3’scomplement just add 1 to the LSB.Example: Find 3’s complement and 2’s complement of 1213?Solution: 2’s complement of 1213
= 222 – 121
Page 24 of 35 Mobin
= 1013
And 3’s complement of 1213
= 2’s complement + 1= 1013+ 1= 1023
R’s AND (R-1)’s COMPLEMENT OF BASE 4 NUMBER SYSTEM
In this system base is 4 so R = 4 and R-1 = 3 thus 4’s complement in this numbersystem is (4n)10-N and 3’s complement in this system is {(4n)10-1)}-N.Example: Find the 3’s complement and 4’s complement of 1304?Solution: 3’s complement of 1304
= {(43)10-1)} – 1304
= 6310– 1304
= 6310– 2810
= 3510
= 2034
4’s complement of 1304
= (43)10– 1304
= 6410– 1304
= 6410– 2810
= 3610
= 2044
The shortcut method for this system is as follows: first subtract each bit of numberfrom 3 and then take them together for 3’s complement and for 4’s complementadd 1 to the LSB.Example: Find the 3’s complement and 4’s complement of 1304?Solution: 3’s complement of 1304
= 333 – 130= 2034
4’s complement of 1304
= 3’s complement of 1304 + 1
Page 25 of 35 Mobin
= 2034+ 1= 2044
R’s AND (R-1)’s COMPLEMENT OF BASE 5 NUMBER SYSTEM
This number system has 4’s and 5’s complement so 4’s complement for thisnumber system is {(5n)10-1)}-N and 5’s complement is (5n)10-N.Example: Find the 4’s complement and 5’s complement of 2245?Solution: 4’s complement of 2245
= {(53)10-1)} – 2245
= 12410– 2245
= 12410– 6410
= 6010
= 2205
5’s complement of 2245
= (53)10– 2245
= 12510– 2245
= 12510– 6410
= 6110
=2215
The shortcut method for 4’s complement is as: we have to subtract each digit of thegiven number from 4. And for 5’s complement just add 1 to the 4’s complement.4’s complement of 2245
= 444 – 224= 2205
5’s complement of 2245
= 4’s complement of 2245 + 1= 2205+ 1= 2215
R’s AND (R-1)’s COMPLEMENT OF BASE 6 NUMBER SYSTEM
6 is the base of this system so R = 6 and R-1 = 5 thus 6’s complement is equal to
Page 26 of 35 Mobin
(6n)10-N and 5’s complement is equal to {(6n)10-1)}-N.Example: Find 5’s complement and 6’s complement of (530)6?Solution: 5’s and 6’s complement of 5306 is found as:5’s complement of 5306
= {(63)10-1)} – 5306
= 21510– 5306
= 21510– 19810
= 1710
= 256
6’s complement of 5306
= (63)10– 5306
= 21610– 5306
= 21610– 19810
= 1810
= 266
By shortcut method we can solve it as we have solved the above problems of base3, 4 or 5. In this system the starting digit is 0 and the last digit is 5 so repeat theabove method.5’s complement of 5306
= 555 – 530= 256
6’s complement of 5306
= 5’s complement of 5306 + 1= 256+ 1= 266
R’s AND (R-1)’s COMPLEMENT OF BASE 7 NUMBER SYSTEM
The base 7 number system has 6’s and 7’s complement so R = 7 and R-1 = 6 thus6’s complement is {(7n)10-1)} – N and 7’s complement is (7n)10– N.Example: Find the 6’s complement and 7’s complement of (653)7 ?Solution: 6’s complement of 6537
= {(73)10-1)} – 6537
Page 27 of 35 Mobin
= 34210– 6537
= 34210– 33210
= 1010
= 137
7’s complement of 6537
= (73)10– 6537
= 34310– 6537
= 34310– 33210
= 1110
= 147
The above problem can also be solved by a shortcut method as: subtract each digitof the given number from 6 and then take them as a whole number. For 7’scomplement add one to the 6’s complement of the given number. Thus the aboveproblem is solved as:6’s complement of 6537
= 666 – 653= 137
7’s complement of 6537
= 6’s complement of 6537 + 1= 137+ 1= 147
R’s AND (R-1)’s COMPLEMENT OF OCTAL NUMBER SYSTEM
In octal number system there is 7’s complement and 8’s complement because hereR = 8 and R-1 = 7. Now 7’s complement of octal number is {(8n)10-1)} – N and 8’scomplement of octal number is (8n)10 – N.Example: Find 7’s complement and 8’s complement of the octal number(172)8?Solution: The 7’s and 8’s complement of 1728 is found as:7’s complement of 1728
= {(83)10-1)} – 1728
= 51110– 1728
Page 28 of 35 Mobin
= 51110– 12210
= 38910
= 6058
8’s complement of 1728
= (83)10– 1728
= 51210– 1728
= 51210– 12210
= 39010
= 6068
In short the above problem can be solved by subtracting each digit from 7 for 7’scomplement and add 1 to the 7’s complement to find 8’s complement of givenoctal number.7’s complement of 1728
= 777 – 172= 6058
8’s complement of 1728
= 7’s complement of 1728 + 1= 6058+ 1= 6068
R’s AND (R-1)’s COMPLEMENT OF BASE 9 NUMBER SYSTEM
The base 9 number system has R = 9 and R-1 = 8 so 8’s complement and 9’scomplement of base 9 number system are {(9n)10-1)} – N and (9n)10 – Nrespectively.Example: Find 8’s complement and 9’s complement of 8079?Solution:8’s complement of 8079
= {(93)10-1)} – 8079
= 72810 – 8079
= 72810 – 65510
= 7310
= 819
Page 29 of 35 Mobin
9’s complement of 8079
= (93)10– 8079
= 72910 – 8079
= 72910 – 65510
= 7410
= 829
The shortcut method for this problem is shown below:8’s complement of 8079
= 888 – 807= 819
9’s complement of 8079
= 8’s complement of 8079+ 1= 819 + 1= 829
R’s AND (R-1)’s COMPLEMENT OF DECIMAL NUMBER SYSTEM
The base of decimal number system is 10 since there are 10 distinguish digits inthis system starting from 0 to 9. In this system R = 10 and R-1 = 9 thus 9’scomplement of decimal number is {(10n)10-1)} – N and 10’s complement is(10n)10 – N.Example: Find 9’s and 10’s complement of the decimal number 40010?9’s complement 40010
= {(103)10-1)} – 40010
= 99910– 40010
= 59910
10’s complement 40010
= (103)10– 40010
= 1000 – 40010
= 60010
The shortcut method for 9’s complement and 10’s complement of decimal numberis shown below:9’s complement 40010
Page 30 of 35 Mobin
= 999 – 400= 59910
10’s complement 40010
= 9’s complement 40010 + 1= 59910+ 1= 60010
R’s AND (R-1)’s COMPLEMENT OF BASE 11 NUMBER SYSTEM
In this system there are 11 digits. The last digit of this system is represented by theEnglish alphabet A which is equivalent to 10 in decimal number system. Here R =11 and R-1 = 10. Thus 10’s complement of this number system is {(11n)10-1)} – Nand 11’s complement of this system is (11n)10 – N.Example: Find 10’s complement and 11’s complement of 1A111?Solution: 10’s complement and 11’s complement of 1A111 is found as:10’s complement of 1A111
= {(113)10-1)} – 1A111
= 133010– 1A111
= 133010– 23210
= 109810
= 90911
11’s complement of 1A111
= (113)10– 1A111
= 133110– 1A111
= 133110– 23210
= 109910
= 90A11
To find 10’s complement of 1A111 by shortcut method we subtract each digit of thegiven number from A which is equal to 10. And for 11’s complement add 1 to thevalue of 10’s complement of 1A111. So the given problem is solved as:10’s complement of 1A111
= AAA – 1A1= 90911
11’s complement of 1A111
= 10’s complement of 1A111 + 1
Page 31 of 35 Mobin
= 90911+ 1= 90A11
R’s AND (R-1)’s COMPLEMENT OF BASE 12 NUMBERSYSTEM
Here the base of the number system is 12. In this system the last two digits are represented by
A and B which are equivalent to 10 and 11. The digits are as: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A and B.
Here R = 12 and R-1 = 11 thus 11’s complement is equal to {(12n)10-1)} – N and 12’s
complement is equal to (12n)10– N.
Example: Find 11’s complement and 12’s complement of AB012?
Solution: 11’s complement and 12’s complement of AB012 is as follows:
11’s complement of AB012
= {(123)10-1)} – AB012
= 172710– AB012
= 172710– 157210
= 15510
= 10B12
12’s complement of AB012
= (123)10– AB012
= 172810– AB012
= 172810– 157210
= 15610
= 11012
We can solve these problems by another method: for 11’s complement subtract each digit from
B and for 12’s complement add 1 to 11’s complement of the given number.
11’s complement of AB012
= BBB – AB0
= 10B12
11’s complement of AB012
= 11’s complement of AB012 + 1
= 10B12+ 1
= 11012
Page 32 of 35 Mobin
R’s AND (R-1)’s COMPLEMENT OF BASE 13 NUMBER SYSTEM
In this system R = 13 and R-1 = 12 so 12’s complement and 13’s complements areas follows: 12’s complement of base 13 number system = {(13n)10-1)} – N and 13’scomplement of base 13 number system = (13n)10 – N.Example: Find 12’s complement and 13’s complement of ABC13?Solution: 12’s complement of ABC13
= {(133)10-1)} – ABC13
= 219610– ABC13
= 219610– 184510
= 35110
= 21013
13’s complement of ABC13
= (133)10– ABC13
= = 219710– ABC13
= 219710– 184510
= 35210
= 21113
By shortcut method:12’s complement of ABC13
= CCC – ABC= 21013
13’s complement of ABC13
= 12’s complement of ABC13 + 1= 21013+ 1= 21113
R’s AND (R-1)’s COMPLEMENT OF BASE 14 NUMBER SYSTEM
For base 14 number system R = 14 and R-1 = 13 so 14’s complement of base 14number system is (14n)10 – N and 13’s complement of this system is {(14n)10-1)} –N.Example: Find 14’s complement and 13’s complement of D1514?
Page 33 of 35 Mobin
Solution: Here base is 14 so let’s use above two formulas to find 14’s and 13’scomplement of D1514.14’s complement of D1514
= (143)10– D1514
= 274410– D1514
= 274410– 256710
= 17710
= C914
13’s complement of D1514
= {(143)10-1)} – D1514
= 274310– D1514
= 274310– 256710
= 17610
= C814
Shortcut method for this problem is as follows: (D = 13)13’s complement of D1514
= DDD – D15= C814
14’s complement of D1514
= 13’s complement of D1514 + 1= C814+ 1= C914
R’s AND (R-1)’s COMPLEMENT OF BASE 15 NUMBER SYSTEM
Base 15 number system has 15’s complement and 14’s complement which are asfollows:15’s complement of base 15 = (15n)10 – N14’s complement of base 15 = {(15n)10-1)} – NExample: Find 15’ complement and 14’s complement of AE015?Solution: The solution of the above problem using the above two formulas:
Page 34 of 35 Mobin
14’s complement of AE015
= {(153)10-1)} – AE015
= 337410– AE015
= 337410– 246010
= 91410
= 40E14
15’s complement of AE015
= (153)10– AE015
= 337510– AE015
= 337510– 246010
= 91510
= 41015
Shortcut method:14’s complement of AE015
= EEE – AE0= 40E15
15’s complement of AE015
= 14’s complement of AE015 + 1= 40E15+ 1= 41015
R’s AND (R-1)’s COMPLEMENT OF HEXADECIMAL NUMBER SYSTEM
Hexadecimal number system has 15’s complement and 16’s complement. Here R =16 and R-1 = 15 thus we can write:15’s complement of hexadecimal number = {(16n)10-1)} – N16’s complement of hexadecimal number = (16n)10 – NExample: Find 15’s complement and 16’s complement of the hexadecimalnumber F916?
Page 35 of 35 Mobin
Solution: 15’s complement of hexadecimal number F916
= {(162)10-1)} – F916
= 25510– F916
= 25510– 24910
= 610
= 616
16’s complement of hexadecimal number F916
= (162)10– F916
= 25610– F916
= 25610– 24910
= 710
= 716
Shortcut method:15’s complement of hexadecimal number F916
= FF – F9= 616
16’s complement of hexadecimal number F916
= 15’s complement of hexadecimal number F916 + 1= 616+ 1= 716