0% found this document useful (0 votes)
7 views25 pages

Understanding Binary Codes in Digital Logic

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views25 pages

Understanding Binary Codes in Digital Logic

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CSE_2323

Binary Codes

Course Teacher: Mujibur Rahman Maruf 1


Digital Logic Design
Course code: CSE-2323
Credit Hour: 3 Hours
Md. Mujibur Rahman Maruf
Assistant Lecturer,
Dept. of CSE, IIUC
Mujiburmaruf.cuet17@[Link]

International Islamic University


) Chittagong(IIUC)
Course Teacher: Mujibur Rahman Maruf 2
BINARY CODES
Digital Codes or Binary Codes:
A group of binary digits is known as a binary code or a digital code.
Numeric Code:
Digital code represented by the number is known as a numeric code.
Classification:

The codes are broadly classified into


1. Weighted code
2. Non-weighted code
3. Reflective code
4. Sequential code
5. Error detecting and correcting codes
Course Teacher: Mujibur Rahman Maruf 3
Classification

Course Teacher: Mujibur Rahman Maruf 4


Weighted codes
the position of each number represent a specific weight.
In these codes each decimal digit is represented by a group of four [Link] Nibble

(Examples:8421, 2421 Code)


each digit is assigned a specific weight according to its position. For example, in
8421/BCD code, 1001 the weights of 1, 1, 0, 1 (from left to right) are 8, 4, 2 and 1
respectively.

Course Teacher: Mujibur Rahman Maruf 5


8421 or BCD code
THE 8421 BCD CODE
BCD stands for Binary-Coded Decimal.

A BCD number is a four-bit binary group that represents


one of the ten decimal digits 0 through 9.

Example:
Decimal number 4926 4 9 2 6

8421 BCD coded number 0100 1001 0010 0110


Course Teacher: Mujibur Rahman Maruf 6
8421 or BCD code
THE 8421 BCD CODE

• (BCD) is a type of binary code used to represent a given decimal number in


an equivalent binary form.
• The BCD equivalent of a decimal number is written by replacing each decimal
digit in the integer and fractional parts with its four-bit binary equivalent.
• The BCD code described above is more precisely known as the 8421 BCD
code .
As an example, the BCD equivalent of (23.15)10 is written as (0010 0011.0001
0101)BCD

Course Teacher: Mujibur Rahman Maruf 7


BCD Addition
BCD ADDITION:- THE 8421 BCD CODE
Addition of BCD (8421) is performed by adding two digits of binary, starting from
least significant digit. In case if the result is an illegal code (greater than 9) or if
there is a carry out of one then add 0110(6) and add the resulting carry to the next
most significant.
For example:-

Course Teacher: Mujibur Rahman Maruf 8


BCD Addition

Course Teacher: Mujibur Rahman Maruf 9


BCD Addition

1 Marks.

(47+65)=?

Course Teacher: Mujibur Rahman Maruf 10


BCD Addition
BCD ADDITION:-

For example:-
Add 8765 with 3943 using BCD addition.
Solution:-

Course Teacher: Mujibur Rahman Maruf 11


Non-weighted code

Non-weighted codes:
The non-weighted codes are not positionally weighted. In other words,
codes that are not assigned with any weight to each digit position.
Example: Excess-3(XS-3) and Gray Codes.
Excess-3 code
Excess-3 codes are Non-weighted and can be obtained by adding 3 to each decimal digit then
It can be represented by using 4 bit binary number for each digit.

Course Teacher: Mujibur Rahman Maruf 12


Non-weighted code
An Excess-3 equivalent of a given binary number is obtained using the following steps:
•Find the decimal equivalent of the given binary number.
•Add +3 to each digit of decimal number.
•Convert the newly obtained decimal number back to binary number to get required excess-3 equivalent.

•These are following excess-3 codes for decimal digits –


Decimal BCD 8421 Excess – 3 code
BCD + 0011
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
Course Teacher: Mujibur Rahman Maruf 13
Gray Code
Gray code:
Gray code has a property that two successive numbers differ in only one bit

Applications:
It is used in analog to digital conversion, input / output devices.
It is used to reduce errors that occur in data transmission.
Course Teacher: Mujibur Rahman Maruf 14
. Binary to Gray conversion
• The MSB of the gray code is the MSB of the binary number.

• Perform XOR operation between the MSB and the second significant bit of the
binary number.

• XOR the second and third significant bits of the binary, the result is the third
significant bit of the gray code.

• Repeat the process till the end of the LSB of the binary number

Course Teacher: Mujibur Rahman Maruf 15


Gray to Binary conversion
•The MSB of the binary is same as the MSB of gray code.

•Perform the XOR operation between the MSB of the binary and
the second significant bit of gray code the result is the second significant bit of binary.

•Perform the XOR operation between the second significant bit of binary and the third
significant bit of gray code the result is the third significant bit of binary.

•Repeat the process until all the gray code bits are XOR.

Course Teacher: Mujibur Rahman Maruf 16


Reflective and sequential code

A code is said to be reflective when the code for


9 is the complement for the code 0
8 is the complement for the code 1
7 is the complement for the code 2
6 is the complement for the code 3

Sequential codes:
A code is said to be sequential when each succeeding code is binary number
greater than its preceding code.
Eg: 8421 code and Excess-3 code

Course Teacher: Mujibur Rahman Maruf 17


Self complimenting code

For self rcomplimenting code must to be fulfilled this condition

(W4 +W3 +W2 +W1=9)

For 8421 code =8+4+2+1=15 (8421 is not self complimenting code)


For 4221 code =4+2+2+1=9 (4221 is self complimenting code)
For 2421 code =2+4+2+1=9 (2421 is self-complimenting code
For 5421 code =5+4+2+1=12((5421 is not self complimenting code)

Course Teacher: Mujibur Rahman Maruf 18


Parity codes

used for the purpose of detecting errors during the transmission of binary information. The
parity code is a bit that is included with the binary data to be transmitted.
Based on the number of 1’s in the transmitted data, the parity code is of two types.

1. 1. Even parity code


2. Odd parity code

Course Teacher: Mujibur Rahman Maruf 19


Parity codes
Even parity code:
If the total number of 1 bits in the word including parity
bit is Even, then such a parity code is said to be Even
parity code.

Odd parity code:


If the total number of 1 bits in the word including parity bit is
odd, then such a parity code is said to be
odd parity code.

The following table shows the even and odd parity bits for 4 bit
data word
The simple parity will not detect two errors within the same word. To detect and correct
error in the word Hamming code is used.
Course Teacher: Mujibur Rahman Maruf 20
Hamming code

Hamming code
Hamming code is a set of error-correction codes that can be used to detect and
correct the errors that can occur when the data is moved or stored from the sender
to the receiver. It is technique developed by R.W. Hamming for error correction.

Redundant bits/parity bits


Redundant bits are extra binary bits that are generated and added to the
information-carrying bits of data transfer to ensure that no bits were lost during
the data transfer.

Course Teacher: Mujibur Rahman Maruf 21


Generation of hamming code
Selecting the number of parity bits:
The number of parity bits to be chosen depends on word [Link] parity bits are even parity bits
Let n be the number of information or data bits, then the number of parity bits P is determined from
the following formula,
2P ≥ n + P + 1
Example:
if 4-bit information is to be transmitted, then n=4. The number of parity bits is determined by the
trial and error method
Let P=2, we get,
22 ≥ 4 + 2+ 1
The above equation implies 4 not greater than or equal to 7. So let’s choose another value of P=3.
23 ≥ 4 + 3+ 1
Now, the equation satisfies the condition. So number of parity bits, P=3. The
bit designation is

Course Teacher: Mujibur Rahman Maruf 22


Example:Generation of hamming code

[Link] determine the value of P1, the sequence as (1,3,5,7).As the value of location 3
is 1, location 5 is 1, and location 7 is 1. So a number of one is the sequence is three,
which is an odd number. So to satisfy even parity, the value of P1 must be 1.

[Link] determine the value of P2, first,The sequence is (2,3,6,7). the digits from
the location number we get (P2,1,0,1). So a number of ones are two. Which is an
even number. So to satisfy even parity, the value of P2 must be zero.

[Link] determine the value of P3, first, The sequence is (4,5,6,7). the digits from
the location number we get, (P3, 1,0,1). So the number of one’s is two. Which is
an even number. So to satisfy even parity, the value of P3 must be zero.

[Link], after obtaining the values of P1, P2, and P3, the complete hamming code
along with the data message is given as

Course Teacher: Mujibur Rahman Maruf 23


Hamming Code Detection with Even Parity
A hamming code 1110101 is received at the receiver [Link] are the correct data bits.

7 6 5 4 3 2 1
D4 D3 D2 P3 D1 P2 P1
1 1 1 0 1 0 1

the values of locations 1,3,5, and 7 becomes (1,1,1,1,). So a For wrong parity palce [Link] write parity place 0
number of 1 is the sequence is [Link] is an even number .
So P1 parity bit is right p3 P2 P1

the values of locations 2,3,6, and 7 becomes (0,1,1,1,).


1 1 0

So a number of 1 is the sequence is [Link] is odd


number . So P2 parity bit is wrong Decimal value of 110 is 6 .it indicates that there is
error occurred in bit number [Link] bit number 6
the values of locations 4,5,6, and 7 becomes (0,1,1,1,). So will be 0.
a number of 1 is the sequence is [Link] is odd so correct data is 1 of hamming code will be 1011
number . So P3 parity bit is wrong
Course Teacher: Mujibur Rahman Maruf 24
Course Teacher: Mujibur Rahman Maruf 25

You might also like