1.3-DE Unit 1 - CODES
1.3-DE Unit 1 - CODES
1.3-DE Unit 1 - CODES
NUMBER SYSTEMS
& CODES
Topic 1.3
CODES
1
By -Prof. Sonali B. Jadhav
CODES
• In the coding, 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.
• Gray Code
• BCD Code
• Excess -3 Code
• ASCII Code
• Error Detection and Correction: Hamming
Codes
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. In these codes each decimal digit is represented by a
group of four bits.
Weighted Code
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.
Binary Coded Decimal (BCD) code
• BCD ADDITION
1
• BCD SUBTRACTION
2
11
BCD ARITHMETIC
• BCD ADDITION
1
12
BCD ADDITION
13
Case 1- Sum is equal to or less than 9 and carry is 0
Eg.-Addition of 2 and 6 in BCD
Decimal BCD
2 0010
+ 6 + 0110
----------- 1 1 ---- carry bit
8 --------------
0 1000
1 7
Add 57 and 26 in BCD = ??
BCD ARITHMETIC
• BCD SUBTRACTION
2
18
• BCD SUBTRACTION
Digital 0 1 2 3 4 5 6 7 8 9
Digit
9’s 9 8 7 6 5 4 3 2 1 0
Comple
ment
• BCD SUBTRACTION
Eg.A-B
Step 1-Obtain 9’s complement of number B.
52-89=??
• BCD SUBTRACTION – 10’s
Complement Method
Eg .A-B
Step 1-Obtain 10’s complement of number B.
3-8 =??
Excess-3 Code
Excess-3 code-
The Excess-3 code is also called as XS-3 code.
It is non-weighted code used to express decimal
numbers. The Excess-3 code words are derived
from the 8421 BCD code words adding (0011)2
or (3)10 to each code word in 8421. The excess-
3 codes are obtained as follows −
Excess-3 Code
Sequential code
Eg. 1-Obtain the XS-3 Code for (428)-
4 2 8 Decimal
Eg. 2– 247.6
2 4 7 . 6 Decimal
0010 0100 0111 . 0110 BCD
+3 0011 0011 0011 . 0011
-------------------------------
0101 0111 1010 . 1001
Gray Code
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.
Reflective
Property
Reflective
Property
Gray Code
Step 1-
1. TheMSB (Most Significant Bit) of the gray code will
be exactly equal to the first bit of the given binary
number.
How to Convert Binary to Gray Code
Step 2 -The second bit of the code will be exclusive-or
(XOR) of the first and second bit of the given binary
number, i.e if both the bits are same the result will be 0
and if they are different the result will be 1.
Alphanumeric codes
ASCII Code -
7 6 5 4 3 2 1
1 0 0 1 0 1 1
4 B
Using ASCII Table code word for character “ f ” =??
Extended ASCII Characters
Code Conversions-
1. Binary to BCD
2. BCD to Binary
3. BCD to Excess-3
4. Excess-3 to BCD
Binary to BCD Conversion
Step1 =(53)10
Step 2 = Convert into Binary - 110101
=??
Q1)Convert (47.3)7 into BCD ,Excess -3 and Gray Code.
STEP 3-
Conversion to excess 3- Decimal + 3 = 3 5 . 4 2 8 5 = 6 8. 7 5 11 8
= (0110 1000 . 0111 0101 1011 1000)xs -3
1 1 0 0 1 0 . 1 1 0 1 1 gray
Error Detection & Correction Codes
1.Parity Checking
2.Cyclic Redundancy Check (CRC)
3.Check Sum
Parity Checking
To detect and correct the errors, additional bits are added to the data bits at the
time of transmission.
The additional bits are called parity bits. They allow detection or correction of the
errors.
The data bits along with the parity bits form a code word.
Parity Checking of Error Detection
It is the simplest technique for detecting and correcting errors. The MSB of an 8-bits
word is used as the parity bit and the remaining 7 bits are used as data or message
bits. The parity of 8-bits transmitted word can be either even parity or odd parity.
Even parity -- Even parity means the number of 1's in the given word including the parity bit
should be even (2,4,6,....).
Odd parity -- Odd parity means the number of 1's in the given word including the parity bit
should be odd (1,3,5,....)
. Use of Parity Bit
The parity bit can be set to 0 and 1 depending on the type of the parity required.
For even parity, this bit is set to 1 or 0 such that the no. of "1 bits" in the entire word is even.
Shown in fig. (a).
For odd parity, this bit is set to 1 or 0 such that the no. of "1 bits" in the entire word is odd.
Shown in fig. (b).
How Does Error Detection Take Place?
Parity checking at the receiver can detect the presence of an error if the parity
of the receiver signal is different from the expected parity. That means, if it is
known that the parity of the transmitted signal is always going to be "even" and
if the received signal has an odd parity, then the receiver can conclude that the
received signal is not correct. If an error is detected, then the receiver will
ignore the received byte and request for retransmission of the same byte to the
transmitter.
NOTE: The counting of data bits will include the parity bit also.
Limitations of parity Checking –
1 1 0 0 0 0 0 1
Parity Data bit Data bit Data bit Data bit Data bit Data bit Data bit
bit 7 6 5 4 3 2 1
H 0 1 0 0 1 0 0 0
O 1 1 0 0 1 1 1 1
L 1 1 0 0 1 1 0 0
E 1 1 0 0 0 1 0 1
Parity bit
Hamming Code
This error detecting and correcting code technique is developed by R.W.Hamming . This
code not only identifies the error bit, in the whole data sequence and it also corrects it.
This code uses a number of parity bits located at certain positions in the codeword. The
number of parity bits depends upon the number of information bits. The hamming code
uses the relation between redundancy bits and the data bits and this code can be
applied to any number of data bits.(2 types – 7 bit & 15 bit)
In the above considered example, we have 4 data bits and 3 parity bits. So the
total codeword to be transmitted is of 7 bits (4 + 3). We generally represent the
data sequence from right to left, as shown below.
= ????
Hamming Code
Detection and Correction of Errors-
-After Hamming Code Transmitted , at the receiver it is decoded to get the data back
-If all the 4 bit groups mentioned above possess the even parity then the received code
word is correct i.e. it does not contain Errors.
- But if the parity is not even then error exists. Such an error can be located by forming a
three bit number out of three parity checks. This process became clear by solving the
example
Hamming Code
Detection and Correction of Errors –
Eg.- A seven bit Hamming Code is received as 1110101.what is the correct code? Assume the
parity to be even.
Hamming Code
Example − Suppose that an incoming message 11110101101 is received (Even
Hamming Code).
Step 1 − At first the number of redundant bits are calculated using the formula 2r ≥ m + r + 1.
Here, m + r + 1 = 11 + 1 = 12. The minimum value of r such that 2r ≥ 12 is 4.
P1 = even_parity(1, 3, 5, 7, 9, 11) = 0
P2 = even_parity(2, 3, 6, 7, 10, 11) = 0
P4 = even_parity (4, 5, 6, 7) = 0
P8 = even_parity (8, 9, 10, 11) = 0
Step 4 - Since the value of the check bits c1c2c3c4 = 0000 = 0, there are no errors in this
message.
Hamming Code
= ????