CST203 - M1 Ktunotes - in
CST203 - M1 Ktunotes - in
Number Systems
If base or radix of a number system is ‘r’, then the numbers present in that
number system are ranging from zero to r-1. The total numbers present in that
number system is ‘r’.
The following number systems are most commonly used.
• Decimal Number system
• Binary Number system
• Octal Number system
• Hexadecimal Number system
part.
• the part of the number that lies to the right of the octal point is known as fractional
part.
The following two types of operations take place, while converting decimal number into its
equivalent binary number.
• Division of integer part and successive quotients with base 2.
• Multiplication of fractional part and successive fractions with base
Example
Consider the decimal number 58.25. Here, the integer part is 58 and fractional part is 0.25.
58/2 29 0 LSB
29/2 14 1
14/2 7 0
7/2 3 1
3/2 1 1
½ 0 1 MSB
⇒5810 = 1110102
Therefore, the integer part of equivalent binary number is 111010.
0.25 x 2 0.5 0
0.5 x 2 1.0 1
0X2 0 0
⇒.2510 = .012
Therefore, the fractional part of equivalent binary number is .01
⇒58.2510 = 111010.012
The following two types of operations take place, while converting decimal number into its
equivalent octal number.
• Division of integer part and successive quotients with base 8.
• Multiplication of fractional part and successive fractions with base 8.
Example
Consider the decimal number 58.25. Here, the integer part is 58 and fractional part is 0.25.
Step 1 − Division of 58 and successive quotients with base 8.
Operation Quotient Remainder
58/8 7 2
7/8 0 7
⇒5810 = 728
Therefore, the integer part of equivalent octal number is 72.
0.25 x 8 2.00 2
- 0.00 -
⇒ ..2510 = .28
Therefore, the fractional part of equivalent octal number is .2
⇒ 58.2510 = 72.28
Therefore, the octal equivalent of decimal number 58.25 is 72.2.
The following two types of operations take place, while converting decimal number into its
equivalent hexa-decimal number.
Example
Consider the decimal number 58.25. Here, the integer part is 58 and decimal part is 0.25.
Step 1 − Division of 58 and successive quotients with base 16.
58/16 3 10=A
3/16 0 3
⇒ 5810 = 3A16
Therefore, the integer part of equivalent Hexa-decimal number is 3A.
Step 2 − Multiplication of 0.25 and successive fractions with base 16.
Operation Result Carry
0.25 x 16 4.00 4
- 0.00 -
⇒.2510 = .416
Therefore, the fractional part of equivalent Hexa-decimal number is .4.
⇒58.2510 = 3A.416
Therefore, the Hexa-decimal equivalent of decimal number 58.25 is 3A.4.
We know that the bases of binary and octal number systems are 2 and 8 respectively. Three
bits of binary number is equivalent to one octal digit, since 23 = 8.
Follow these two steps for converting a binary number into its equivalent octal number.
• Start from the binary point and make the groups of 3 bits on both sides of
binary point. If one or two bits are less while making the group of 3 bits, then
include required number of zeros on extreme sides.
• Write the octal digits corresponding to each group of 3 bits.
Example
Consider the binary number 101110.01101.
Step 1 − Make the groups of 3 bits on both sides of binary point. 101
110.011 01
Here, on right side of binary point, the last group is having only 2 bits. So, include one zero
on extreme side in order to make it as group of 3 bits.
⇒ 101 110.011 010
Step 2 − Write the octal digits corresponding to each group of 3 bits. ⇒
101110.0110102 = 56.328
Therefore, the octal equivalent of binary number 101110.01101 is 56.32.
We know that the bases of binary and Hexa-decimal number systems are 2 and 16 respectively.
Four bits of binary number is equivalent to one Hexa-decimal digit, since 24 = 16.
Follow these two steps for converting a binary number into its equivalent Hexa decimal
number.
• Start from the binary point and make the groups of 4 bits on both sides of binary point.
If some bits are less while making the group of 4 bits, then include required number of
zeros on extreme sides.
• Write the Hexa-decimal digits corresponding to each group of 4 bits.
Example
Consider the binary number 101110.01101
Step 1 − Make the groups of 4 bits on both sides of binary point. 10
1110.0110 1
Here, the first group is having only 2 bits. So, include two zeros on extreme side in order to
make it as group of 4 bits. Similarly, include three zeros on extreme side in order to make the
last group also as group of 4 bits.
⇒ 0010 1110.0110 1000
Step 2 − Write the Hexa-decimal digits corresponding to each group of 4 bits.
⇒ 00101110.011010002 = 2E.6816
Therefore, the Hexa-decimal equivalent of binary number 101110.01101 is 2E.68.
For converting an octal number into its equivalent decimal number, first multiply the digits of
octal number with the respective positional weights and then add all those products.
Example
Consider the octal number 145.23.
Mathematically, we can write it as
145.238 = (1 × 82) + (4 × 81) + (5 × 80) + (2 × 8-1) + (3 × 8-2)
⇒ 145.238 = 64 + 32 + 5 + 0.25 + 0.05 = 101.3
⇒ 145.238 = 101.310
Therefore, the decimal equivalent of octal number 145.23 is 101.3.
The process of converting an octal number to an equivalent binary number is just opposite to
that of binary to octal conversion. By representing each octal digit with 3 bits, we will get the
equivalent binary number.
Example
Consider the octal number 145.23.
Represent each octal digit with 3 bits.
145.238 = 001100101.0100112
The value doesn’t change by removing the zeros, which are on the extreme side. ⇒
145.238 = 1100101.0100112
Therefore, the binary equivalent of octal number 145.23 is 1100101.010011.
Follow these two steps for converting an octal number into its equivalent Hexa decimal
number.
⇒ 1A5.216 = 421.12510
Therefore, the decimal equivalent of Hexa-decimal number 1A5.2 is 421.125.
The process of converting Hexa-decimal number into its equivalent binary number is just
opposite to that of binary to Hexa-decimal conversion. By representing each Hexa-decimal
digit with 4 bits, we will get the equivalent binary number.
Example
Consider the Hexa-decimal number 65.4C
Represent each Hexa-decimal digit with 4 bits.
65.4C16 = 01100101.010011002
The value doesn’t change by removing the zeros, which are at two extreme sides. ⇒
65.4C16 = 1100101.0100112
Therefore, the binary equivalent of Hexa-decimal number 65.4C is 1100101.010011.
Follow these two steps for converting Hexa-decimal number into its equivalent
octal number.
Example
Consider the Hexa-decimal number 65.4C
In previous example, we got the binary equivalent of Hexa-decimal number 65.4C
as 1100101.010011.
By following the procedure of binary to octal conversion, we will get
1100101.0100112 = 145.238
⇒65.4C16 = 145.238
Therefore, the octal equivalent of Hexa-decimal number 65.4C is 145.23.
Binary Arithmetic
Binary Addition
In fourth case, a binary addition is creating a sum of (1 + 1 = 10) i.e. 0 is written as sum
column and 1 as carry.
Example
Binary Subtraction
Example
Binary Multiplication
Example: Using the binary multiplication rules, multiply 1102 and 112.
Example: Using the binary multiplication rules, find the product of 110112 and 1012.
Solution:
GIven multiplicand = 11011 and multiplier = 101
On multiplying we get,
Binary Division
Binary division problems can be solved by using the long division method, which is one of
the most efficient and easiest ways to divide binary numbers. These are the steps to be
followed in a binary division operation:
• Step 1: Compare the divisor with the dividend. If the divisor is larger, place 0 as
the quotient, then bring the second bit of the dividend down. If the divisor is
smaller, multiply it with 1 and the result becomes the subtrahend. Then, subtract
the subtrahend from the minuend to get the remainder.
• Step 2: Then bring down the next number bit from the dividend portion and
perform step 1 again.
• Step 3: Repeat the same process until the remainder becomes zero or the whole
dividend is divided.
Step1: Since the zero in the most significant bit position doesn't change the value of the
number, let's remove it from both the dividend and divisor. So the dividend becomes 11010,
and the divisor becomes 101.
Step 2: Let us use the long-division method. In this step, compare the divisor 101 with the
first digit in the dividend 11010, since the divisor is smaller, it will be multiplied with 1 and
the result will be the subtrahend.
As per the binary multiplication rules:
• 1×1=1
• 1×0=0
• 0×1=0
• 0×0=0
So, 101 × 1 = 101, and this result is written below.
Step 3: Subtract the subtrahend 101 from the minuend 110.
As per the binary subtraction rules,
• 0 - 1 = 1, we need to borrow 1 from the next more significant bit.
• 0-0=0
• 1-1=0
• 1-0=0
When we apply the above rules, this is how the calculation is done:
• For the first digit on the right, we have to subtract (0 - 1). So, we borrow a 1 from
the digit on the left or the next higher order digit. Therefore, the result is 1.
• Then, (0 - 0 = 0) since the number in the next higher order digit becomes 0 after
borrowing.
• 1 - 1 = 0 in the second next higher order digit.
• So, 110 - 101 = 001, and this result is written below.
Step 4: As per the rules of division, the next least significant bit comes down, and the divisor
is multiplied by 1. Since the result, 101 is bigger than the minuend 0011, this step cannot be
completed. Then, we have to go to the next step
Step 5: We write 0 as the next bit of the quotient and then, the least significant bit 0 comes
down.
Step 6: Again the divisor is multiplied by 1 and the result is written as 101 × 1 = 101.
Step 7: Now we are at the final step. As per the binary subtraction, we subtract 101 from 110.
We get, 110 - 101 = 001. The remainder is similar to Step 3, as all the numbers are the same.
The binary division operation is completed now and we get the following result.
• Quotient = 101
• Remainder = 001 = 1
Solution:
Solution:
Complements
Complements are used in the digital computers in order to simplify the subtraction operation
and for the logical manipulations. For each radix-r system (radix r represents base of number
system) there are two types of complements.
S.N. Complement Description
Example 1: (1011000)2
This number has a base of 2, which means it is a binary number. So, for the binary
numbers, the value of r is 2, and r-1 is 2-1=1. So, we can calculate the 1's and 2's
complement of the number.
={(27 )10-1}-(1011000)2
={(128)10-1}-(1011000)2
={(127)10}-(1011000)2
=11111112-10110002
=0100111
=(27 )10-(1011000)2
=(128)10-(1011000)2
=100000002-10110002
=01010002
Example 2: (155)10
This number has a base of 10, which means it is a decimal number. So, for the decimal
numbers, the value of r is 10, and r-1 is 10-1=9. So, we can calculate the 10's and 9's
complement of the number.
={(103 )10-1}-(155)10
=(1000-1)-155
=999-155
=(844)10
=(103 )10-(15510
=1000-155
=(845)10
Example 3: (172)8
This number has a base of 8, which means it is an octal number. So, for the octal
numbers, the value of r is 8, and r-1 is 8-1=7. So, we can calculate the 8's and 7's
complement of the number.
={(83 )10-1}-(172)8
=((512)10-1)-(132)8
=(511)10-(122)10
=(389)10
=(605)8
=(83 )10-(172)8
=(512)10-1728
=51210-12210
=39010
=6068
Example 4: (F9)16
This number has a base of 16, which means it is a hexadecimal number. So, for the
hexadecimal numbers, the value of r is 16, and r-1 is 16-1=15. So, we can calculate the
16's and 15's complement of the number.
{(162 )10-1}-(F9)16
(256-1)10-F916
25510-24910
(6)10
(6)16
As the binary system has base r = 2. So the two types of complements for the binary system
are 2's complement and 1's complement.
1's complement
1’s complement: is obtained by subtracting each digit in the number from 1 or by simply
inverting the digits.
The 1's complement of a number is found by changing all 1's to 0's and all 0's to 1's. This is
called as taking complement or 1's complement. Example of 1's Complement is as follows.
2's complement
The 2's complement of binary number is obtained by adding 1 to the Least Significant Bit
(LSB) of 1's complement of the number.
2's complement = 1's complement + 1
Example of 2's Complement is as follows.
The bits present in the un-signed binary number holds the magnitude of a number. That means,
if the un-signed binary number contains ‘N’ bits, then all N bits represent the magnitude of the
number, since it doesn’t have any sign bit.
Example
Consider the decimal number 108. The binary equivalent of this number is 1101100. This is
the representation of unsigned binary number.
10810 = 11011002
It is having 7 bits. These 7 bits represent the magnitude of the number 108.
The Most Significant Bit MSB of signed binary numbers is used to indicate the sign of the
numbers. Hence, it is also called as sign bit. The positive sign is represented by placing ‘0’ in
the sign bit. Similarly, the negative sign is represented by placing ‘1’ in the sign bit.
If the signed binary number contains ‘N’ bits, then N−1 bits only represent the magnitude of
the number since one-bit MSB is reserved for representing sign of the number.
There are three types of representations for signed binary numbers
• Sign-Magnitude form
• 1’s complement form
• 2’s complement form
Representation of a positive number in all these 3 forms is same. But, only
the representation of negative number will differ in each form.
Example
Consider the positive decimal number +108. The binary equivalent of magnitude of this
number is 1101100. These 7 bits represent the magnitude of the number 108. Since it is
positive number, consider the sign bit as zero, which is placed on left most side of magnitude.
+10810 = 011011002
Therefore, the signed binary representation of positive decimal number +108 is 01101100. So,
the same representation is valid in sign-magnitude form, 1’s complement form and 2’s
complement form for positive decimal number +108.
Sign-Magnitude form
In sign-magnitude form, the MSB is used for representing sign of the number and the
remaining bits represent the magnitude of the number. So, just include sign bit at the left most
side of unsigned binary number. This representation is similar to the signed decimal numbers
representation.
– The most significant bit (MSB) indicates sign (0: positive, 1: negative).
+0 0000 -0 1000
+1 0001 -1 1001
+2 0010 -2 1010
+3 0011 -3 1011
+4 0100 -4 1100
+5 0101 -5 1101
+6 0110 -6 1110
+7 0111 -7 1111
The 1’s complement of a number is obtained by complementing all the bits of signed binary
number. So, 1’s complement of positive number gives a negative number. Similarly, 1’s
complement of negative number gives a positive number.
That means, if you perform two times 1’s complement of a binary number including sign bit,
then you will get the original signed binary number.
Basic idea:
– Positive numbers are represented exactly as in sign-magnitude form.
– Negative numbers are represented in 1’s complement form. •
+0 0000 -0 1111
+1 0001 -1 1110
+2 0010 -2 1101
+3 0011 -3 1100
+4 0100 -4 1011
+5 0101 -5 1010
+6 0110 -6 1001
+7 0111 -7 1000
Example
Consider the negative decimal number -108. The magnitude of this number is 108. We
know the signed binary representation of 108 is 01101100.
It is having 8 bits. The MSB of this number is zero, which indicates positive
number. Complement of zero is one and vice-versa. So, replace zeros by ones and ones
by zeros in order to get the negative number.
−10810 = 100100112
The 2’s complement of a binary number is obtained by adding one to the 1’s complement of
signed binary number. So, 2’s complement of positive number gives a negative number.
Similarly, 2’s complement of negative number gives a positive number.
That means, if you perform two times 2’s complement of a binary number including sign bit,
then you will get the original signed binary number.
Basic idea:
– Positive numbers are represented exactly as in sign-magnitude form.
– Negative numbers are represented in 2’s complement form.
+0 0000 -0 -
+1 0001 -1 1111
+2 0010 -2 1110
+3 0011 -3 1101
+4 0100 -4 1100
+5 0101 -5 1011
+6 0110 -6 1010
+7 0111 -7 1001
Example
Consider the negative decimal number -108.
We know the 1’s complement of (-108)10 is (10010011)2
2’s compliment of 10810 = 1’s compliment of 10810 + 1 =
10010011 + 1
= 10010100
Therefore, the 2’s complement of 10810 is 100101002.
The steps for 1’s complement subtraction of a smaller number from a larger binary number
are as follows:
Step-1: Determine the 1’s complement of the smaller number.
Step-2: Add this to the larger number.
Step-3: Remove the carry and add it to the result. This carry is called end-around-carry.
Note: carry 1 has been added to the addition to get the subtraction of the binary numbers.
Thus, the subtraction is done by actually adding two binary numbers.
Note: no carry has been obtained while subtracting a larger number from a smaller number.
Further, a minus sign has been put.
To subtract a smaller number from a larger number using 2’s complement subtraction,
following steps are to be followed:
Step-1: Determine the 2’s complement of the smaller number
Advantages:
Though both 1’s and 2’s complement method for subtracting binary numbers seems to be
complicated when compared with direct method of subtraction of two binary numbers, both
have advantage when applied using logic circuits, because they allow subtraction to be done
using only addition. The 1‘s and 2’s complement of a binary number can easily be arrived at
using logic circuits; the advantage in 2’s complement subtraction is that the end-around-carry
operation present in 1’s complement method is not involved here.
• BCD or Binary Coded Decimal is that number system or code which has the binary
numbers or digits to represent a decimal number.
In BCD we can use the binary number from 0000-1001 only, which are the decimal
equivalent from 0-9 respectively.
• if a number have single decimal digit then it’s equivalent Binary Coded Decimal will be
the respective four binary digits of that decimal number
• if the number contains two decimal digits then it’s equivalent BCD will be the respective
eight binary of the given decimal number. Four for the first decimal digit and next four
for the second decimal digit.
• Let, (12)10 be the decimal number whose equivalent Binary coded decimal will be
00010010. Four bits from L.S.B is binary equivalent of 2 and next four is the binary
equivalent of 1.
• For 0 to 9 decimal numbers both binary and BCD is equal but when decimal number is
more than one bit BCD differs from binary.
Decimal number Binary number Binary Coded Decimal(BCD)
0 0000 0000
1 0001 0001
2 0010 0010
3 0011 0011
4 0100 0100
5 0101 0101
6 0110 0110
7 0111 0111
8 1000 1000
9 1001 1001
10 1010 0001 0000
11 1011 0001 0001
12 1100 0001 0010
13 1101 0001 0011
14 1110 0001 0100
15 1111 0001 0101
BCD Addition
• Step 1: Add the two BCD numbers, using the rules for binary addition.
• Step 2: If a 4-bit sum is equal to or less than 9, it is a valid BCD number.
• Step 3: If a 4-bit sum is greater than 9, or if a carry out of the 4-bit group is
generated, it is an invalid result. Add 6 (0110) to the 4-bit sum in order to skip the six
invalid BCD code words and return the code to 8421. If a carry results when 6 is
added, simply add the carry to the next 4-bit group.
Solution:
01000011BCD = 4310
00110101BCD = 3510
In the above example, all the 4-bit BCD additions generate valid BCD number, that means
less than 9. So, the final correct result is 7810 = 01111000BCD.
Solution:
01110101BCD = 7510
00110101BCD = 3510
both the BCD code addition generated result larger than 9, so invalid. To get the correct
result, we added 6 (01102) to both the invalid sum. Notice that the carry generated from the
left group is forwarded to the right group. The final correct result is 11010 =
000100010000BCD.
BCD Subtraction
9’s Complement Method
• Find the 9’s complement of the subtrahend
• Add it to the minuend using BCD addition
• If result is invalid BCD, add 6 (0110)
• Shift carry to next bit
• If end around carry is generated add carry to the result, otherwise find the 9’s complement
of the result.
Example: Solve BCD Subtraction using 9’s Complement Method 987.6 – 678.9
Solution
o Find the 9’s complement of the subtrahend 678.9
9 9 9. 9
+ 6 7 8. 9
3 2 1. 0
1 1 0 0 1 0 1 0 1 0 0 0. 0 1 1 0
invalid invalid valid valid
1 0 0 1 0 1 0 0 0 0 1 0 0 0. 0 1 1 0
0 0 1 1 0 0 0 0 1 0 0 0. 0 1 1 1
3 0 8. 7
Example: Solve BCD Subtraction using 10’s Complement Method 987.6 – 678.9
Solution
o Find the 10’s complement of the subtrahend 678.9
9 9 9. 9
+ 6 7 8. 9
3 2 1. 0
+ 1
3 2 1. 1
1 1 0 0 1 0 1 0 1 0 0 0. 0 1 1 1
invalid invalid valid valid
1 1 1
1 1 0 0 1 0 1 0 1 0 0 0. 0 1 1 1
+ 0 1 1 0 0 1 1 0
1 0 0 1 0 1 0 0 0 0 1 0 0 0. 0 1 1 1
0 0 1 0 0 0 0 0 1 0 0 0. 0 1 1 1
+ 1 0 0
0 0 1 1 0 0 0 0 1 0 0 0. 0 1 1 1
3 0 8. 7
Example: Solve BCD Subtraction using 10’s Complement Method 26.25 – 38.26
Solution
o Find the 10’s complement of the subtrahend 38.26
9 9. 9 9
+ 3 8. 2 6
6 1. 7 3
+ 1
6 1. 7 4
1 0 0 0 0 1 1 1. 1 0 0 1 1 0 0 1
8 valid 7 valid 9 valid 9 valid
9 9. 9 9
+ 8 7. 9 9
1 2. 0 0
+ 1
1 2. 0 1
Octal Addition
Example: Solve 4568 - 1238
Solution
4 5 6
+ 1 2 3
? ? ?
6+3 = 9 = (8x1) + 1
5+2+1 = 8 = (8x1) + 0
4+1+1 = 6
1 1
4 5 6
+ 1 2 3
6 0 1
Octal Subtraction
1. General Method
Example
7438 - 5648
7 4 3
- 5 6 4
6 8 8 8+3-4= 7
7 4 3 8+4-6= 5
- 5 6 4 6-5= 1
______
1 5 7
7 7 7
-5 6 4
_______
2 1 3
2. Add Minuend 743 to 7’s complement of Subtrahend (213)
7 4 3
+ 2 1 3
1 1 5 6
7+2= 9 = (8 X 1) + 1
3. carry is generated, add carry to result.
1 5 6
+ 1
1 5 7
Example
7438 - 5648
1. Find 8’s complement of Subtrahend 564
▪ Find 7’s complement of Subtrahend 564
7 7 7
-5 6 4
_______
2 1 3
▪ Add 1 to 7’s complement 213
2 1 3
+ 1
2 1 4
7 4 3
+ 2 1 4
1 1 5 7
7+2= 9 = (8 X 1) + 1
Hexadecimal Addition
4 A 6
+ 1 B 3
? ? ?
6+3 = 9
A+B = 10+11= 21 = (16X1) + 5
4+1+1 = 6
1
4 A 6
+ 1 B 3
6 5 9
Hexadecimal Subtraction
1. General Method
Example
Solve 974B16 – 587C16
9 7 4 B
- 5 8 7 C
? ? ? ?
8 15 15 16
9 7 4 B
- 5 8 7 C
? ? ? ?
A=10, B= 11. C=12, D=14, F=15
16+11-12= 15 = F
15+4-7= 12= C
Dept of CSE| STIST| PAGE 34
15+7-8= 14= E
8-5 =3
8 15 15 16
9 7 4 B
- 5 8 7 C
3 E C F
F-C = 15-12 = 3
F-7 = 15-7 = 8
F-8 = 15-8 = 7
F-5 = 15-5 = 10 = A
F F F F
- 5 8 7 C
A 7 8 3
? ? ? ?
B+3 = 11+3 = 14 = E
4+8=12= C
7+7=14= E
9+A=9+10=19=(16X1) + 3
9 7 4 B
+ A 7 8 3
1 3 E C E
F-1 = 15-1 = 14 = E
F-B=15-11=4
F-C=15-12=3
F F F
- C B 1
3 4 E
? ? ?
E+1 = F
7+4= 11= B
9+3= 12= C
9 7 1
+ 3 4 E
C B F
F F F
- C B F
? ? ?
F-F = 0
F-B= 15- 11 = 4
F-C = 15-12 = 3
F F F
- C B F
3 4 0
Example
Solve 974B16 – 587C16
F-C = 15-12 = 3
F-7 = 15-7 = 8
F-8 = 15-8 = 7
F-5 = 15-5 = 10 = A
F F F F
- 5 8 7 C
A 7 8 3
A 7 8 3
+ 1
A 7 8 4
+ A 7 8 4
? ? ? ?
B+4 = 11+4 = 15 = F
4+8=12= C
7+7=14= E
9+A=9+10=19=(16X1) + 3
9 7 4 B
+ A 7 8 3
1 3 E C F
F F F
- C B 1
? ? ?
A=10, B= 11. C=12, D=14, F=15
F-1 = 15-1 = 14 = E
F-B=15-11=4
F-C=15-12=3
F F F
- C B 1
3 4 E
Find 16’s complement of Subtrahend
3 4 E
+ 1
3 4 F
? ? ?
F+1 = 16 = (16X1)+0
1+7+4= 12= C
9+3= 12= C
1
9 7 1
+ 3 4 F
C C 0
F-0 = F
F-C= 15- 12 = 3
F-C = 15-12 = 3
F F F
- C C 0
3 3 F
Binary Codes
When numbers, letters or words are represented by a specific group of symbols, it is
said that the number, letter or word is being encoded. The group of symbols is called as a
code.
Weighted Codes
Weighted binary codes are those binary codes which obey the positional weight principle.
Each position of the number represents a specific weight. Several systems of the codes are
used to express the decimal digits 0 through 9 (like 8421, 2421 and 84-2-1). In these codes
each decimal digit is represented by a group of four bits.
Weighted codes can be further classified as positively weighted codes (8421, 2421) and
negatively weighted codes (84-2-1).
Non-Weighted Codes
In this type of binary codes, the positional weights are not assigned. The examples of non-
weighted codes are Excess-3 code and Gray code.
8 4 2 1 code
2 4 2 1 code
8 4 -2 -1 code
Excess 3 code
Digit BCD
8 1000
1 0001
6 0110
1 0001
• Then, we add 0011 in both of the BCD code.
Self-complementary property
A self-complementary binary code is a code which is always complimented in itself. By
replacing the bit 0 to 1 and 1 to 0 of a number, we find the 1's complement of the number.
The sum of the 1'st complement and the binary number of a decimal is equal to the binary
number of decimal 9.
The following table shows the various binary codes for decimal digits 0 to 9.
Decimal Digit 8421 Code 2421 Code 84-2-1 Code Excess 3 Code
Gray Codes
The Gray Code is a sequence of binary number systems, which is also known as reflected
binary code. The reason for calling this code as reflected binary code is the first N/2 values
compared with those of the last N/2 values in reverse order. In this code, two consecutive values
are differed by one bit of binary digits. Gray codes are used in the general sequence of
hardware-generated binary numbers. These numbers cause ambiguities or errors when the
transition from one number to its successive is done. This code simply solves this problem by
changing only one bit when the transition is between numbers is done.
The gray code is a very light weighted code because it doesn't depend on the value of the digit
specified by the position. This code is also called a cyclic variable code as the transition of one
value to its successive value carries a change of one bit only.
Error detection and correction code plays an important role in the transmission of data from
one source to another. The noise also gets added into the data when it transmits from one system
to another, which causes errors in the received binary data at other systems. The bits of the data
may change (either 0 to 1 or 1 to 0) during transmission.
It is impossible to avoid the interference of noise, but it is possible to get back the original data.
For this purpose, we first need to detect either an error z is present or not using error detection
codes. If the error is present in the code, then we will correct it with the help of error correction
codes
The error detection codes are the code used for detecting the error in the received
data bitstream. In these codes, some bits are included appended to the original bitstream.
Error detecting codes encode the message before sending it over the noisy channels. The
encoding scheme is performed in such a way that the decoder at the receiving can find the
errors easily in the receiving data with a higher chance of success.
Parity Code
In parity code, we add one parity bit either to the right of the LSB or left to the MSB to the
original bitstream. On the basis of the type of parity being chosen, two types of parity codes
are possible, i.e., even parity code and odd parity code.
Error correction codes are generated by using the specific algorithm used for removing and
detecting errors from the message transmitted over the noisy channels. The error-correcting
codes find the correct number of corrupted bits and their positions in the message. There are
two types of ECCs(Error Correction Codes), which are as follows.
Block codes
in block codes, in fixed-size blocks of bits, the message is contained. In this, the redundant bits
are added for correcting and detecting errors.
Hamming Code
Hamming code is an example of a block code. The two simultaneous bit errors are detected,
and single-bit errors are corrected by this code. In the hamming coding mechanism, the sender
encodes the message by adding the unessential bits in the data. These bits are added to the
specific position in the message because they are the extra bits for correction.