Digital Logic Design
Lecture 5
Binary Codes
What is Binary Codes or Coding?
➢ Binary coding is a system of representing text, numbers, and instructions in
computers using only two digits: 0 and 1.
➢ These codes are the foundation of all digital systems, including computers,
communication devices, and storage systems.
Importance of Binary Codes or Coding
➢ Introduction to Binary Coding
• A system that represents data using only 0s and 1s.
• Used in all digital devices like computers, smartphones, and calculators.
➢ How It Works?
• Each binary digit (bit) is the smallest unit of data.
• Multiple bits form characters, numbers, and instructions for computers.
Importance of Binary Codes or Coding
➢ Importance of Binary Coding
1. Universal Language
• All computers and digital devices use binary to process data.
2. Fast & Efficient
• Binary allows quick processing and easy storage of information.
3. Reliable Communication
• Helps detect and correct errors in data transmission.
Importance of Binary Codes or Coding
➢ Applications of Binary Coding
1. Computers & Software – Used in all programming languages and operating
systems.
2. Digital Communication – Internet, Wi-Fi, and mobile networks transmit data in
binary.
3. Storage Devices – Hard drives, SSDs, and USBs store data in binary form.
Types of Binary Codes in DLD
➢ In Digital Logic Design (DLD), binary codes are classified based on their purpose
and structure. Here are the main types:
1. Weighted Codes
2. Non-Weighted Codes
3. Error Detection and Correction Codes
4. Special-Purpose Codes
Types of Binary Codes in DLD
1. Weighted Codes
These codes assign a specific weight to each bit position.
• Binary Number System (Pure Binary) – Standard positional representation.
• Binary-Coded Decimal (BCD) – Each decimal digit is represented by a 4-bit
binary value (e.g., 9 → 1001).
• Excess-3 (XS-3) Code – A self-complementary code used in arithmetic
operations (e.g., Decimal 5 → 1000).
• 2421 Code – A weighted code where bit positions have weights of 2, 4, 2, and 1.
Types of Binary Codes in DLD
➢ BCD (Binary-Coded Decimal) Codes – What?
• BCD is a binary encoding system where each decimal
digit (0-9) is represented by a 4-bit binary number.
• BCD is mainly used in digital clocks, calculators, and
electronic meters.
Types of Binary Codes in DLD
➢ BCD (Binary-Coded Decimal) Codes – What?
• BCD is a binary encoding system where each decimal
digit (0-9) is represented by a 4-bit binary number.
• BCD is mainly used in digital clocks, calculators, and
electronic meters.
• Generate for 11-20
Types of Binary Codes in DLD
➢ BCD Codes – Why?
• Easy Conversion: Simple to convert between decimal and binary.
• Error Reduction: Reduces computational errors in financial and commercial
applications.
• Efficient for Display Devices: Used in devices that require decimal
representation (e.g., digital clocks).
Types of Binary Codes in DLD
1. Convert 185 to Binary:
• Step 1: Divide 185 by 2 and record the remainder.
• Step 2: Continue dividing the quotient by 2 until you reach 0.
• Binary of 185 = 10111001₂
Types of Binary Codes in DLD
1. Convert 185 to Binary:
• Step 1: Divide 185 by 2 and record the remainder.
• Step 2: Continue dividing the quotient by 2 until you reach 0.
• Binary of 185 = 10111001₂
Types of Binary Codes in DLD
➢ Conversion of 185 to BCD
• Convert each decimal digit separately into a 4-bit binary.
• BCD of 185 = 0001 1000 0101 (in groups of 4 bits)
Types of Binary Codes in DLD
1. Convert 6,248 into Excess-3 (XS-3)
➢ Steps:
• Convert each decimal digit to BCD (Binary-Coded Decimal).
• Add 3 (0011₂) to each BCD value to get the Excess-3 code.
Types of Binary Codes in DLD
1. Convert to Excess-3 (XS-3)
➢ Steps:
• Convert each decimal digit to BCD (Binary-Coded Decimal).
• Add 3 (0011₂) to each BCD value to get the Excess-3 code.
• Generate till 20
Types of Binary Codes in DLD
1. Convert 6,248 into Excess-3 (XS-3)
➢ Steps:
• Convert each decimal digit to BCD (Binary-Coded Decimal).
• Add 3 (0011₂) to each BCD value to get the Excess-3 code.
• Generate till 20
Types of Binary Codes in DLD
Excess-3 of 6,248 = 1001 0101 0111 1011 (Excess-3)
Types of Binary Codes in DLD
Types of Binary Codes in DLD
Types of Binary Codes in DLD
2. Non-Weighted Codes
These codes do not follow a specific positional weight system.
• Gray Code – Only one bit changes between successive numbers, reducing errors
in hardware.
• Alphanumeric Codes – Used to encode letters, numbers, and symbols.
1. ASCII (American Standard Code for Information Interchange) – 7-bit/8-
bit encoding.
2. EBCDIC (Extended Binary Coded Decimal Interchange Code) – Used in
IBM mainframes.
3. Unicode – Supports multiple languages (8-bit, 16-bit, or 32-bit).
Types of Binary Codes in DLD
1. Convert Binary 1011 into Gray Code
➢ Step 1: Write the First Bit as it is
• The first bit of Gray Code is the same as the first bit of Binary
➢ Step 2: Perform XOR Operation for the Next Bits
• Gray code is generated using the formula:
Types of Binary Codes in DLD
Gray Code of 1011 = 1110
Types of Binary Codes in DLD
Types of Binary Codes in DLD
➢ Table of Grey Code
Types of Binary Codes in DLD
3. Error Detection and Correction Codes
These codes help detect and correct errors in data transmission and storage.
• Parity Bit Code – Uses an extra bit to detect errors (Even or Odd Parity).
• Hamming Code – Detects and corrects single-bit errors using redundant bits.
• Cyclic Redundancy Check (CRC) – Used in communication networks for error
detection.
• Checksum Code – Used in data integrity checks (common in network
protocols).
Types of Binary Codes in DLD
4. Special-Purpose Codes
• Self-Complementary Codes – Useful in arithmetic operations (e.g., Excess-3).
• Huffman Code – Used in data compression techniques.
• Manchester Code – A clock-synchronized encoding scheme for data
transmission.
Practice Questions:
➢ Binary to BCD Conversion:
1. Convert 357 (Decimal) to BCD.
2. Convert 642 (Decimal) to BCD.
➢ Binary to Excess-3 Code Conversion:
3. Convert 248 (Decimal) to Excess-3 Code.
4. Convert 519 (Decimal) to Excess-3 Code.
➢ Binary to Gray Code Conversion:
5. Convert 10110 (Binary) to Gray Code.
6. Convert 11100 (Binary) to Gray Code.