1. KUD BSc 3rd SEM : ELECTRONICS : OPTO AND DIGITAL ELECTRONICS
BY : MAHIBOOB ALI K MULLA MSc , Mphil.
Asst.Prof.in electronics , SSGFG COLLEGE NARAGUND
2. Opto and Digital Electronics: Unit 2: Number System
Number System
The mastery over depiction & symbolization of the numbers through performing certain
conversion tasks on them to make then equivalent is called Number System. This forms the
fundamentals of Computers Number system. Computers recognize and converts common man’s
stereotyping of words and letters into numbers.
There are mainly four different groups of Number Systems:
•Decimal System
•Binary System
•Octal System
•Hexadecimal System
3. Decimal Number System
Decimal number system is used in our everyday business. Normally in this genre of rendition non-
identical positions are given to each numeral connoting the number depending upon their setting
points.The units, tens, hundreds, thousands and so on of the decimal number system take
consecutive places to the left of the decimal point to exemplify it. The decimal number system
appoints 10 as its plinth/ base and it houses the 10 diverging numerals, the digits are
0,1,2,3,4,5,6,7,8,9.
29. Subtraction by 1’s Complement
The steps to be followed in subtraction by 1’s
complement are:
i) To write down 1’s complement of the subtrahend.
ii) To add this with the minuend.
iii) If the result of addition has a carry over then it is
dropped and an 1 is added in the last bit.
iv) If there is no carry over, then 1’s complement of
the result of addition is obtained to get the final
result and it is negative.
30. Evaluate:
(i) 110101 – 100101
Solution:
1’s complement of 10011 is 011010. Hence
Minued - 1 1 0 1 0 1
1’s complement of subtrahend - 0 1 1 0 1 0
Carry over - 1 0 0 1 1 1 1
1
0 1 0 0 0 0
The required difference is 1 0 0 0 0
31. (ii) 101011 – 111001
Solution:
1’s complement of 111001 is 000110. Hence
Minued - 1 0 1 0 1 1
1’s complement - 0 0 0 1 1 0
1 1 0 0 0 1
Hence the difference is – 1 1 1 0
(iii) 1011.001 – 110.10
Solution:
1’s complement of 0110.100 is 1001.011 Hence
Minued - 1 0 1 1 . 0 0 1
1’s complement of subtrahend - 1 0 0 1 . 0 1 1
Carry over - 1 0 1 0 0 . 1 0 0
1
0 1 0 0 . 1 0 1
Hence the required difference is 100.101
32. (iv) 10110.01 – 11010.10
Solution:
1’s complement of 11010.10 is 00101.01
1 0 1 1 0 . 0 1
0 0 1 0 1 . 0 1
1 1 0 1 1 . 1 0
Hence the required difference is – 00100.01 i.e. – 100.01
33. Subtraction by 2’s Complement
With the help of subtraction by 2’s complement method we can
easily subtract two binary numbers.
The operation is carried out by means of the following steps:
(i) At first, 2’s complement of the subtrahend is found.
(ii) Then it is added to the minuend.
(iii) If the final carry over of the sum is 1, it is dropped and the
result is positive.
(iv) If there is no carry over, the two’s complement of the sum
will be the result and it is negative.
The following examples on subtraction by 2’s complement will
make the procedure clear:
34. Evaluate:
(i) 110110 - 10110
Solution:
The numbers of bits in the subtrahend is 5 while that of minuend is 6. We
make the number of bits in the subtrahend equal to that of minuend by taking
a `0’ in the sixth place of the subtrahend.
Now, 2’s complement of 010110 is (101101 + 1) i.e.101010. Adding this with
the minuend.
1 1 0 1 1 0 Minuend
1 0 1 0 1 0 2’s complement of subtrahend
Carry over 1 1 0 0 0 0 0 Result of addition
After dropping the carry over we get the result of subtraction to be 100000.
35. (ii) 10110 – 11010
Solution:
2’s complement of 11010 is (00101 + 1) i.e. 00110. Hence
Minued - 1 0 1 1 0
2’s complement of subtrahend - 0 0 1 1 0
Result of addition - 1 1 1 0 0
As there is no carry over, the result of subtraction is negative and is
obtained by writing the 2’s complement of 11100 i.e.(00011 + 1) or 00100.
Hence the difference is – 100.
36. (iii) 1010.11 – 1001.01
Solution:
2’s complement of 1001.01 is 0110.11. Hence
Minued - 1 0 1 0 . 1 1
2’s complement of subtrahend - 0 1 1 0 . 1 1
Carry over 1 0 0 0 1 . 1 0
After dropping the carry over we get the result of subtraction as 1.10.
37. (iv) 10100.01 – 11011.10
Solution:
2’s complement of 11011.10 is 00100.10. Hence
Minued - 1 0 1 0 0 . 0 1
2’s complement of subtrahend - 0 1 1 0 0 . 1 0
Result of addition - 1 1 0 0 0 . 1 1
As there is no carry over the result of subtraction is negative
and is obtained by writing the 2’s complement of 11000.11.
Hence the required result is – 00111.01.
40. Conversion from Binary to Hexadecimal number system
Since number numbers are type of positional number system. That
means weight of the positions from right to left are as 160, 161, 162,
163and so on. for the integer part and weight of the positions from left
to right are as 16-1, 16-2, 16-3and so on. for the fractional part.
Most
Significant
Bit (MSB)
Hexa Point Least Significant Bit (LSB)
16
2
16
1
16
0
16
-1
16
-2
16
-3
256 16 1 1/16 1/256 1/4096
41. Example − Convert binary number 1101010 into hexadecimal number.
First convert this into decimal number:
= (1101010)2
= 1x2 ↑ 6+1x2 ↑ 5+0x2 ↑ 4+1x2 ↑ 3+0x2 ↑ 2+1x2 ↑ 1+0x2 ↑ 0
= 64+32+0+8+0+2+0
= (106)10
Then, convert it into hexadecimal number
= (106)10
= 6x16 ↑ 1+10x16 ↑ 0
= (6A)16 which is answer.
However, there is also a direct method to convert a binary number into
hexadecimal number − grouping which is explained as following below.
42. Using Grouping :
Since, there are only 16 digits (from 0 to 7 and A to F) in hexadecimal number system, so we
can represent any digit of hexadecimal number system using only 4 bit as following below.
So, if you make each group of 4 bit of binary input number, then replace each group of
binary number from its equivalent hexadecial digits. That will be hexadecimal number of
given number. Note that you can add any number of 0’s in leftmost bit (or in most significant
bit) for integer part and add any number of 0’s in rightmost bit (or in least significant bit) for
fraction part for completing the group of 4 bit, this does not change value of input binary
number.
So, these are following steps to convert a binary number into hexadecimal number.
•Take binary number
•Divide the binary digits into groups of four (starting from right) for integer part and start
from left for fraction part.
•Convert each group of four binary digits to one hexadecimal digit.
This is simple algorithm where you have to grouped binary number and replace their
equivalent hexadecimal digit.
43. Example-1 − Convert binary number 1010101101001 into hexadecimal number. Since
there is no binary point here and no fractional part. So,
Therefore, Binary to hexadecimal is,
= (1010101101001)2
= (1 0101 0110 1001)2
= (0001 0101 0110 1001)2
= (1 5 6 9)16
= (1569)16
44. Example-2 − Convert binary number 001100101.110111 into hexadecimal number. Since there
is binary point here and fractional part. So,
Therefore, Binary to hexadecimal is,
= (001100101.110111)2
= (0 0110 0101 . 1101 1100)2
= (0110 0101 . 1101 1100)2
= (6 5 . D C)16
= (65.DC)16
These are above simple conversions binary number to hexadecimal number.
45. Conversion of Hexadecimal to Binary:
Hexadecimal to Binary conversion: Each hexadecimal digit is replaced by its equivalent decimal
digit and each decimal digit is replaced by equivalent 4- bit binary number.
Examples 1:convert hexa decimal (16AF)16 to binary.
Ans: 1H=0001B , 6H=0110B , AH=1010B , FH=1111B .Hence ,
Hexa decimal (16AF)H=(0001 0110 1010 1111) Binary.
Example 2: Convert Hexa decimal (E5C9)16 to Binary.
Ans: (E5C9) Hexa decimal = (1110 0101 1100 1001)Binary.
Example 3: Find binary equivalent of Hexa decimal (D7B8.C4E6) .
Ans: (D7B8.C4E6)H = (1101 0111 1011 1000.1100 0100 1110 0110)B.
Hexa 0 1 2 3 4 5 6 7 8 9 A B C D E F
Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
46. Conversion from Binary to Decimal number system
There are mainly two methods to convert a binary number into decimal
number − using positional notation, and using doubling. These methods are
explained are as following below.
Using Positional Notation
Since number numbers are type of positional number system. That means
weight of the positions from right to left are as 20, 21, 22, 23... and so on for
the integer part and weight of the positions from left to right are as 2-1, 2-2, 2-3,
2-4... and so on for the fractional part.
Most
Significant Bit
(MSB)
Binary Point Least Significant Bit (LSB)
2
2
2
1
2
0
2
-1
2
-2
2
-3
4 2 1 0.5 0.25 0.125
47. Assume any unsigned binary number is bnb(n-1) ... b1b0.b-1b-2 ... b(m-1)bm.
Then the decimal number is equal to the sum of binary digits (bn) times
their power of 2 (2n), i.e., bnb(n-1) ... b1b0.b-1b-2 ... b(m-1)bm = bnx2n+b(n-
1)x2(n-1)+ ... +b1x21+bx020+b-1x2-1+b-22-2+ ...
This is simple algorithm where you have to multiply positional value of
binary with their digit and get the sum of these steps.
Example-1 − Convert binary number 11001010 into decimal number.
Since there is no binary point here and no fractional part. So,
Binary to decimal is,
48. = (1010.1011)2
= 1x2 ↑ 3+0x2 ↑ 2+1x2 ↑ 1+0x2 ↑ 0+1x2 ↑ -1+0x2 ↑ -2+1x2 ↑ -3+1x2 ↑ -4
= 8+0+2+0+0.5+0+0.125+0.0625
= (10.6875)10
Using Doubling:
This is simple method to convert a binary number into decimal number, you need to start
from leftmost digit (or MSB) from the input. Take the most significant bit (MSB), right
down, then multiply by 2 with it and add second leftmost bit, store it as current result,
then again multiple by 2 with current result and add third leftmost bit, update this value as
current result and follow this till addition of least significant bit (LSB or rightmost bit).
Since you are doubling (multiplying by 2) each time, so this method is known as
Doubling.
These are simple algorithm is explained below in steps: − Write down the binary number.
•Starting from the left, double your previous total and add the current digit..Double your
current total and add the next leftmost digit..Repeat the previous step.S
49. For example, Convert binary number 11101110 into decimal number.
According to above algorithm, Binary to decimal is,
= (11101110)2
= 1
= 1*2+1 =3
= 3*2+1=7
= 7*2+0=14
= 14*2+1=29
= 29*2+1=59
= 59*2+1=119
= 119*2+0=238
= (238)10
These are above two simple methods to convert a binary number into decimal number.
50. Conversion from :Hexadecimal to Decimal number system
There are various indirect or direct methods to convert a hexadecimal number
into decimal number. In an indirect method, you need to convert a hexadecimal
number into binary or octal number, then you can convert it into decimal number.
Example − Convert hexadecimal number F1 into decimal number.
First convert it into binary number,
= (F1)16
= (1111 0001)2
Because in binary, value of F and 1 are 1111 and 0001 respectively. Then convert it
into decimal number multiplying power of its position of base.
= (1x2↑7+1x2↑6+1x2↑5+1x2↑4+0x2↑3+0x2↑2+0x2↑1+1x2↑0)10
= (241)10
51. However, there is a simple direct method to convert a hexadecimal number
to decimal number. Since, there are only 16 digits (from 0 to 9 and A to F)
in hexadecimal number system, so we can represent any digit of
hexadecimal number system using only 4 bit as following below.
Hexa 0 1 2 3 4 5 6 7
Binary 0000 0001 0010 0011 0100 0101 0110 0111
Hexa 8 9 A=10 B=11 C=12 D=13 E=14 F=15
Binary 1000 1001 1010 1011 1100 1101 1110 1111
Hexadecimal number system provides convenient way of converting large binary
numbers into more compact and smaller groups. These are weights of hexadecimal
of respective position of hexadecimal (value of base is 16).
Most Significant Bit (MSB) Hexa Point Least Significant Bit (LSB)
16 ↑ 2 16 ↑ 1 16 ↑ 0 16 ↑ -1 16 ↑ -2 16 ↑ -3
256 16 1 1/16 1/256 1/4096
52. Example-1 − Convert hexadecimal number ABCDEF into decimal number.Since
value of Symbols − A, B, C, D, E, F are 10, 11, 12, 13, 14, 15 respectively.
Therefore equivalent decimal number is,
= (ABCDEF)16
= (10x165+11x164+12x163+13x162+14x161+15x160)10
= (10485760+720896+49152+3328+224+15)10
= (11259375)10 which is answer.
Example-2 − Convert hexadecimal number 1F.01B into decimal number.
Since value of Symbols: B and F are 11 and 15 respectively. Therefore
equivalent decimal number is,
= (1F.01B)16
= (1x161+15x160 +0x16-1+1x16-2+11x16-3)10
= (31.0065918)10 which is answer.
53. CONVERTING DECIMAL TO HEXADECIMAL
Steps: Divide the decimal number by 16. Treat the division as an integer
division. Write down the remainder (in hexadecimal).
Divide the result again by 16. Treat the division as an integer division.
Repeat step 2 and 3 until result is 0.
The hex value is the digit sequence of the remainders from the last to first.
Note: a remainder in this topic refers to the left over value after
performing an integer division.
HEXADECIMAL 0 1 2 3 4 5 6 7 8 9
A B C D E F
DECIMAL 0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15
54. Example 2
Convert the number 256 DECIMAL to HEXADECIMAL
DIVISION RESULTREMAINDER (in HEX)
256 / 16 16 0
16 / 161 0
1 / 16 0 1
ANSWER 100
Example 3
Convert the number 921 DECIMAL to HEXADECIMAL
DIVISION RESULTREMAINDER (in HEX)
921 / 16 57 9
57 / 163 9
3 / 16 0 3
ANSWER 399
55. Example 4:
Convert the number 188 DECIMAL to HEXADECIMAL
DIVISION RESULTREMAINDER
(in HEX)
188 / 16 11 C (12 decimal)
11 / 160 B (11 decimal)
ANSWER BC
Note that here, the answer would not be 1112, but BC. Remember to write down the
remainder in hex, not decimal.
Example 5:
Convert the number 100 DECIMAL to HEXADECIMAL
DIVISION RESULTREMAINDER
(HEX)
100 / 16 6 4
6 / 16 0 6
ANSWER 64
56. Example 6
Convert the number 590 DECIMAL to HEXADECIMAL
DIVISION RESULT REMAINDER
(HEX)
590 / 16 36 E (14 decimal)
36 / 162 4 (4 decimal)
2 / 16 0 2 (2 decimal)
ANSWER 24E
Example 7:
Convert the number 1128 DECIMAL to HEXADECIMAL
DIVISION RESULT REMAINDER
1128/16 70 8
70/16 4 6
4/16 0 4
ANSWER:[ 468]H
Note: For fractional numbers successive multiplication is used.
57. Example : Convert Hexadecimal of 0.16 to Decimal.
Step 1
We multiply 0.16 by 16 and take the integer part
0.16 x 16 = 2.56
Integer part = 2
Fractional part = 0.56
As, fractional part is not equal to 0 so again multiply fractional part by 16.
Step 2
We multiply 0.56 by 16 and take the integer part
0.56 x 16 = 8.96
Integer part = 8
Fractional part = 0.96
As, fractional part is not equal to 0 so again multiply fractional part by 16.If zero stop else
continue till fractional part becomes zero or number of digits after decimal point.
Answer: (0.16)10 = (0.28F5C...)16
58. Octal number system:
The octal number system uses only eight digits (0 through 7) , but the
conversion from decimal to octal and binary to octal follows the same
pattern as for hexadecimal. It is a 3-bit binary code from (000 to 111).In octal
Digits 8 & 9 are not used.
64. BCD codes:
A binary code will have some unassigned bit combinations if the number of
element in the set is not a multiple power of two. The decimal digit from
such a set is the binary code distinguished among 10 elements must
contain at least 4 bits and this code is called BCD. So in BCD, 6 out of 16
possible combinations remain unassigned and each decimal digit is treated
differently and assigned the corresponding 4 bit code for every digit. A
number with K decimal digit will require 4K bits in BCD. For e.g. BCD for
132 is 0001 0011 0010.
Advantages
Even though THE BCD representations requires more numbers of bit then in
binary, it is easier for data manipulations and the observations for the user can
understand decimal codes rather than binary.
Decimal 0 1 2 3 4 5 6 7 8 9
8421 BCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
65. BCD addition:
IN BCD addition the normal addition process is followed if the sum
is less than 10 (1010)2. But if the um is greater than or equal to 10
(1010)2 we have to add 6(0110) to the sum. The addition of 6
(0110)2 to the binary sum converts it to the correct digit and
produces a carry as required. This is because the carry is the most
significant bit position of the binary sum and decimal carry differ by
16-10=6
Example
4 (0100) + 5 (0101) = 9 (1001)
4 (0100) + 8 (1000) = 12 (1100) which is greater than 10 so adding
6 (0110) to it we get 10010. (0010)2 is 2
66. Gray code:
It is the non-weighted code and it is not arithmetic codes. That means there are no
specific weights assigned to the bit position. It has a very special feature that, only
one bit will change each time the decimal number is incremented as shown in fig.
As only one bit changes at a time, the gray code is called as a unit distance code.
The gray code is a cyclic code. Gray code cannot be used for arithmetic operation.
67. Application of Gray code:
Gray code is popularly used in the shaft position encoders.
A shaft position encoder produces a code word which represents the
angular position of the shaft.
Binary to Gray conversion: Example: Let assume the Binary code digits be
bo, b1, b2, b3 whereas the particular Gray Code can be attained based on
the following concept.
68. Ex : Convert binary value b3, b2, b1, b0 = 1101 to gray code g3, g2, g1, g0
70. Gray to Binary Code Converter:
This gray to binary conversion method also uses the working concept of the EX-OR logic
gate among the bits of gray as well as binary bits.
we can get the binary values like b3 = g3, b2 = b3 XOR g2, b1= b2 XOR g1, b0 = b1 XOR g0.
71. Example of Gray to Binary Code Converter:
Let assume the Gray Code digits g3, g2, g1, g0 whereas the particular Binary code digits
are bo, b1, b2, b3 can be attained based on the following concept.
we can get the binary values like b3 = g3, b2 = b3 XOR g2, b1= b2 XOR g1, b0 = b1 XOR g0.
72. For example take the gray value g3, g2, g1, g0 = 0011 and find the
binary code b3, b2, b1, b0
b3=g3=0
b2 = b3 XOR g2 = 0 XOR 0 =0
b1= b2 XOR g1= 0 XOR 1 = 1
b0= b1 XOR g0= 1 XOR 1 = 0
The final binary code for the value of gray 0011 is 0010
74. ASCII code:
ASCII (American Standerd Code For Information Interchange ) is a 7-bit
character set containing 128 characters. It contains the numbers from 0-9,
the upper and lower case English letters from A to Z, and some special
characters. The character sets used in modern computers (Key Boards) , in
HTML, and on the Internet, are all based on ASCII. Ex:Key Board