SlideShare a Scribd company logo
Chapter1: Digital Systems and Binary
Numbers
Lecture5- Study Binary Codes
Engr. Arshad Nazir, Asst Prof
Dept of Electrical Engineering
SEECS 1
Fall 2022
Objectives
• Study Binary Codes
• Perform Arithmetic operations in BCD using 10’s
Complement method
2
Fall 2022
Binary Codes
• Digital systems use discrete elements of information represented with
binary codes (i.e., a pattern of 0’s and 1’s). The codes should be in binary
because computers have circuits that represent and manipulate 0’s and
1’s.
• An n-bit binary code is a group of n bits that can represent up to 2n distinct
combinations of 1’s and 0’s.
 Each distinct combination represents a single symbol in the computer.
 The bit combination of an n-bit code is determined from the count in
binary from 0 to 2n-1. Each element must be assigned a unique binary
bit combination, and no two elements can have the same value.
• Although the minimum number of bits required to code 2n distinct
quantities is n, there is no maximum number of bits that can be used for a
binary code.
• Codes can be categorized as numeric and alphanumeric used for numbers
and transmission of textual data. Fall 2022 3
BCD Code (8,4,2,1)
• The most common representation for binary digits is the binary coded
decimal (BCD) form which is a binary assignment of the decimal numbers.
 This code is the simplest, most intuitive binary code for decimal digits
and uses the same weights as a binary number, but only encodes the
first ten values from 0 to 9 (6 out of 16 possible combinations remains
unassigned ).
 A number with k distinct decimal digits will require 4k bits in BCD.
 Each digit of a decimal value is converted to its respective binary
representation.
 BCD number needs more bits than its equivalent binary value?
• Each decimal digit in BCD code can be represented as shown in the next
slide.
Binary Coded Decimal Code (BCD)
Fall 2022 5
BCD Addition
• BCD only represents each of the decimal digitals 0 through 9 as a single 4-bit
binary value. BCD is a numeral code used in arithmetic operations in digital
machines. Addition is the most important operation because the other three
operations (subtraction, multiplication, and division can be accomplished using
addition. Following rules apply:
 Add the two BCD numbers, using the rules of binary addition.
 If a 4-bit sum is equal to or less than 9, it is a valid BCD number.
 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 invalid
states and return the code to 8421. If a carry results when 6 is added, simply
add the carry to the next significant 4-bit group.
• Some BCD addition examples are:
Fall 2022 6
Multi-Digit BCD Addition
Fall 2022 7
BCD Arithmetic
• BCD arithmetic involving negative numbers uses the 10’s complement for
representing the negative numbers including the sign digit.
 0 (0000) represents a positive sign and 9 (1001) represents a negative
sign
• As an example, imagine we want to add
(+257) + (-160) = +97 Are these signed?
• Note: To obtain 10’s complement of a BCD number, we first take the 9’s
complement (by subtraction of each digit from 9) and then add one to
least significant digit
Perform subtraction (-257) - (+160) both signed and unsigned?
Fall 2022 8
Other Decimal Codes
• There are various other decimal codes that can be used:
 BCD (8, 4, 2, 1)
 2, 4, 2, 1
 Excess-3 code. (adds binary 0011 to the BCD code)
 8, 4, -2, -1
 Gray Code
 ASCII Character Code
 Error-Detecting Code
• Each bit has a "weight" associated with it and you can compute the
decimal value by adding the weights where a 1 exists in the code-
word.
Fall 2022 9
Four Different Binary Codes
Fall 2022 10
Gray Code
• The Gray (reflected) code is named after Frank Gray who patented it
for shaft encoders in 1953. It is un-weighted and non-arithmetic code;
that is, there are no specific weights assigned to the bit positions
• Some of the uses of Gray code are:-
 Conversion of physical variables like position or voltage that have a
continuous range of values to a digital representation.
 A different use of Gray codes appears in low-power CMOS logic
circuits that count up or down.
• Gray code is cyclic code i.e any n-bit code can be generated form n-1
bit code by taking reflection along the mirror and padding the two
halves with 0’s and 1’s respectively.
• The advantage of Gray code over straight binary number sequence is
that only one bit in the code group changes when going from one
number to the next (unit distance code).
Fall 2022 11
Gray Code Cont…
• This property is important in many applications, such as optical shaft angle
encoders, where error susceptibility increases with the number of bit
changes between adjacent numbers in a sequence.
• Optical shaft encoder is a disc attached to rotating shaft to measure its
rotational position. The disc contains areas that are clear for binary 1 and
opaque for binary 0. An illumination source is placed on one side of the
disc, and optical sensors, one for each of the bits to be encoded are placed
on the other side of the disc. When a clear region lies between the source
and a sensor, the sensor responds to the light with a binary 1 output. When
opaque region lies between the source and the sensor, the sensor
responds to the dark with a binary 0.
• The optical shaft encoder using 3-Bit Gray code for positions 0 through 7 is
shown in the next slide.
Fall 2022 12
Fall 2022 13
Gray Code Vs Binary Code
• Compare the number of bits
changing when going from
one number to the next for a
three-bit Binary and Gray
Code:
 In Gray code it is always
1-bit change (unit-
distance code).
 Can you guess the
applications where this
important property can
be used in digital
applications?
Fall 2022 14
Gray Code
Cont…
Fall 2022 15
Conversion from Binary to Gray Code
• Binary to Gray code Conversion: The following rules apply:
 The most significant bit (left-most) in the Gray code is the same as the
corresponding MSB in the binary number.
 Going from left to right, add each adjacent pair of binary code bits to get the
next Gray code bit and discard carries. Which addition?
 For example, the conversion of binary number 10110 to Gray Code is as follows
 The Gray Code is 11101.
Fall 2022 16
Conversion from Gray to Binary Code
• Gray to Binary code Conversion: The following rules apply:
 The most significant bit (left-most) in the Binary code is the same as the
corresponding MSB in the Gray code.
 Add each Binary code bit generated to the Gray code bit in the next adjacent
position and discard carries.
 For example, the conversion of Gray number 11011 to Binary code is as follows
 The binary number is 10010.
Fall 2022 17
More Decimal Codes
0111
0101
0100
1100
1101
Excess-3
Fall 2022 18
Your Turn
• Write 196510 in the following codes:
 8, 4, 2, 1=
 8, 4, -2, -1=
 6, 3, 1, 1=
 Excess-3=
 Gray=
• Which of these codes are self-complementing?
Fall 2022 19
The End
20
Fall 2022

More Related Content

PPTX
micro processor and its architecture unit1.pptx
PPTX
Digital Logic BCA TU Chapter 2.2
PPT
BCD,GRAY and EXCESS 3 codes
PPTX
Digital Module 1.pptx Digital logic design
PPTX
Digital Logic-Lecture19.pptx
PPT
Code conversion r006
PPTX
12.Representation of signed binary numbers. Binary codes - BCD code, Gray co...
PDF
numbering system binary and decimal hex octal
micro processor and its architecture unit1.pptx
Digital Logic BCA TU Chapter 2.2
BCD,GRAY and EXCESS 3 codes
Digital Module 1.pptx Digital logic design
Digital Logic-Lecture19.pptx
Code conversion r006
12.Representation of signed binary numbers. Binary codes - BCD code, Gray co...
numbering system binary and decimal hex octal

Similar to Lecture5 Chapter1- Binary Codes.pdf (20)

PPTX
Codes r005
PPT
Student IP Addressing Tutorial.ppt
PDF
Unit 1 Class Notes Printed digital Electronics.pdf
PPTX
5_2019_01_03!03_33_00_PM.pptx
PPTX
Chapter 5: Cominational Logic with MSI and LSI
PPTX
Combinational Circuits digital design logic
PPTX
Unit 1 data representation and computer arithmetic
PPTX
Module_3_Codes and Arithmetic operation.pptx
PDF
Digital electronics
PPTX
Unit-1 (DLD) Lecture 2.pptx
PDF
Binary_Codes.pdfhfkhvfkdhvbhfvfdhfgffhfdhyf
PPTX
PPTX
Introduction to Computer Logical Organization
PPTX
Coding Schemes related dld lecture it is dld
PDF
Digital Electronics Codes.pdf
PDF
Binary to gray converter using xor
PDF
Digital Electronics- Number systems & codes
Codes r005
Student IP Addressing Tutorial.ppt
Unit 1 Class Notes Printed digital Electronics.pdf
5_2019_01_03!03_33_00_PM.pptx
Chapter 5: Cominational Logic with MSI and LSI
Combinational Circuits digital design logic
Unit 1 data representation and computer arithmetic
Module_3_Codes and Arithmetic operation.pptx
Digital electronics
Unit-1 (DLD) Lecture 2.pptx
Binary_Codes.pdfhfkhvfkdhvbhfvfdhfgffhfdhyf
Introduction to Computer Logical Organization
Coding Schemes related dld lecture it is dld
Digital Electronics Codes.pdf
Binary to gray converter using xor
Digital Electronics- Number systems & codes
Ad

More from UmerKhan147799 (8)

PDF
Lecture6 Chapter1- ASCII Code, Error Detection and Correction Codes, and Bina...
PDF
Lecture6 Chapter4- Design Magnitude Comparator Circuit, Introduction to Decod...
PDF
Lecture6 Chapter3- Function Simplification using Quine-MacCluskey Method.pdf
PDF
Lecture4 Chapter4- Design 4-bit Lookahead Carry Binary Adder-Subtractor Circu...
PDF
Lecture5 Chapter2- Positive and Negative Logic.pdf
PDF
Lecture4 Chapter3- Non-Degenerate Forms.pdf
PDF
Lecture5 Chapter4- Design Decimal Adder and Binary Multiplier Circuits.pdf
PDF
Lecture5 Chapter3- Exclusive-OR Function and its Applications in Digital Desi...
Lecture6 Chapter1- ASCII Code, Error Detection and Correction Codes, and Bina...
Lecture6 Chapter4- Design Magnitude Comparator Circuit, Introduction to Decod...
Lecture6 Chapter3- Function Simplification using Quine-MacCluskey Method.pdf
Lecture4 Chapter4- Design 4-bit Lookahead Carry Binary Adder-Subtractor Circu...
Lecture5 Chapter2- Positive and Negative Logic.pdf
Lecture4 Chapter3- Non-Degenerate Forms.pdf
Lecture5 Chapter4- Design Decimal Adder and Binary Multiplier Circuits.pdf
Lecture5 Chapter3- Exclusive-OR Function and its Applications in Digital Desi...
Ad

Recently uploaded (20)

PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
DOCX
573137875-Attendance-Management-System-original
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Welding lecture in detail for understanding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Well-logging-methods_new................
PPTX
Geodesy 1.pptx...............................................
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Internet of Things (IOT) - A guide to understanding
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
573137875-Attendance-Management-System-original
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Welding lecture in detail for understanding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Embodied AI: Ushering in the Next Era of Intelligent Systems
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
CH1 Production IntroductoryConcepts.pptx
Well-logging-methods_new................
Geodesy 1.pptx...............................................
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx

Lecture5 Chapter1- Binary Codes.pdf

  • 1. Chapter1: Digital Systems and Binary Numbers Lecture5- Study Binary Codes Engr. Arshad Nazir, Asst Prof Dept of Electrical Engineering SEECS 1 Fall 2022
  • 2. Objectives • Study Binary Codes • Perform Arithmetic operations in BCD using 10’s Complement method 2 Fall 2022
  • 3. Binary Codes • Digital systems use discrete elements of information represented with binary codes (i.e., a pattern of 0’s and 1’s). The codes should be in binary because computers have circuits that represent and manipulate 0’s and 1’s. • An n-bit binary code is a group of n bits that can represent up to 2n distinct combinations of 1’s and 0’s.  Each distinct combination represents a single symbol in the computer.  The bit combination of an n-bit code is determined from the count in binary from 0 to 2n-1. Each element must be assigned a unique binary bit combination, and no two elements can have the same value. • Although the minimum number of bits required to code 2n distinct quantities is n, there is no maximum number of bits that can be used for a binary code. • Codes can be categorized as numeric and alphanumeric used for numbers and transmission of textual data. Fall 2022 3
  • 4. BCD Code (8,4,2,1) • The most common representation for binary digits is the binary coded decimal (BCD) form which is a binary assignment of the decimal numbers.  This code is the simplest, most intuitive binary code for decimal digits and uses the same weights as a binary number, but only encodes the first ten values from 0 to 9 (6 out of 16 possible combinations remains unassigned ).  A number with k distinct decimal digits will require 4k bits in BCD.  Each digit of a decimal value is converted to its respective binary representation.  BCD number needs more bits than its equivalent binary value? • Each decimal digit in BCD code can be represented as shown in the next slide.
  • 5. Binary Coded Decimal Code (BCD) Fall 2022 5
  • 6. BCD Addition • BCD only represents each of the decimal digitals 0 through 9 as a single 4-bit binary value. BCD is a numeral code used in arithmetic operations in digital machines. Addition is the most important operation because the other three operations (subtraction, multiplication, and division can be accomplished using addition. Following rules apply:  Add the two BCD numbers, using the rules of binary addition.  If a 4-bit sum is equal to or less than 9, it is a valid BCD number.  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 invalid states and return the code to 8421. If a carry results when 6 is added, simply add the carry to the next significant 4-bit group. • Some BCD addition examples are: Fall 2022 6
  • 8. BCD Arithmetic • BCD arithmetic involving negative numbers uses the 10’s complement for representing the negative numbers including the sign digit.  0 (0000) represents a positive sign and 9 (1001) represents a negative sign • As an example, imagine we want to add (+257) + (-160) = +97 Are these signed? • Note: To obtain 10’s complement of a BCD number, we first take the 9’s complement (by subtraction of each digit from 9) and then add one to least significant digit Perform subtraction (-257) - (+160) both signed and unsigned? Fall 2022 8
  • 9. Other Decimal Codes • There are various other decimal codes that can be used:  BCD (8, 4, 2, 1)  2, 4, 2, 1  Excess-3 code. (adds binary 0011 to the BCD code)  8, 4, -2, -1  Gray Code  ASCII Character Code  Error-Detecting Code • Each bit has a "weight" associated with it and you can compute the decimal value by adding the weights where a 1 exists in the code- word. Fall 2022 9
  • 10. Four Different Binary Codes Fall 2022 10
  • 11. Gray Code • The Gray (reflected) code is named after Frank Gray who patented it for shaft encoders in 1953. It is un-weighted and non-arithmetic code; that is, there are no specific weights assigned to the bit positions • Some of the uses of Gray code are:-  Conversion of physical variables like position or voltage that have a continuous range of values to a digital representation.  A different use of Gray codes appears in low-power CMOS logic circuits that count up or down. • Gray code is cyclic code i.e any n-bit code can be generated form n-1 bit code by taking reflection along the mirror and padding the two halves with 0’s and 1’s respectively. • The advantage of Gray code over straight binary number sequence is that only one bit in the code group changes when going from one number to the next (unit distance code). Fall 2022 11
  • 12. Gray Code Cont… • This property is important in many applications, such as optical shaft angle encoders, where error susceptibility increases with the number of bit changes between adjacent numbers in a sequence. • Optical shaft encoder is a disc attached to rotating shaft to measure its rotational position. The disc contains areas that are clear for binary 1 and opaque for binary 0. An illumination source is placed on one side of the disc, and optical sensors, one for each of the bits to be encoded are placed on the other side of the disc. When a clear region lies between the source and a sensor, the sensor responds to the light with a binary 1 output. When opaque region lies between the source and the sensor, the sensor responds to the dark with a binary 0. • The optical shaft encoder using 3-Bit Gray code for positions 0 through 7 is shown in the next slide. Fall 2022 12
  • 14. Gray Code Vs Binary Code • Compare the number of bits changing when going from one number to the next for a three-bit Binary and Gray Code:  In Gray code it is always 1-bit change (unit- distance code).  Can you guess the applications where this important property can be used in digital applications? Fall 2022 14
  • 16. Conversion from Binary to Gray Code • Binary to Gray code Conversion: The following rules apply:  The most significant bit (left-most) in the Gray code is the same as the corresponding MSB in the binary number.  Going from left to right, add each adjacent pair of binary code bits to get the next Gray code bit and discard carries. Which addition?  For example, the conversion of binary number 10110 to Gray Code is as follows  The Gray Code is 11101. Fall 2022 16
  • 17. Conversion from Gray to Binary Code • Gray to Binary code Conversion: The following rules apply:  The most significant bit (left-most) in the Binary code is the same as the corresponding MSB in the Gray code.  Add each Binary code bit generated to the Gray code bit in the next adjacent position and discard carries.  For example, the conversion of Gray number 11011 to Binary code is as follows  The binary number is 10010. Fall 2022 17
  • 19. Your Turn • Write 196510 in the following codes:  8, 4, 2, 1=  8, 4, -2, -1=  6, 3, 1, 1=  Excess-3=  Gray= • Which of these codes are self-complementing? Fall 2022 19