SlideShare a Scribd company logo
1 of 31
Binary Codes
Binary codes are of two types:
 Weighted Codes.
 Non weighted or Unweighted Codes.
Weighted codes
• Each binary bit is assigned a “Decimal weight”.
8 4 2 1
Ex: (0 1 0 1)2= 510
• Each group of 4 bits, the sum of the weights of those binary bits whose
value is 1 is equal to the decimal number which they represent.
Weighted Codes
• 1.Positive Weighted Code 2.Negative Weighted Code
• Examples:
– 8421 --642-3
– 2421 --84-2-1
– 5211
– 5421
Examples of Weighted Codes
BCD(Binary Coded Decimal) CODE
• It is a weighted code.
• It is a special code used to represent single decimal digit.
• Each decimal digit from 0 to 9 is coded by a 4-bit binary number.
• It has six invalid states 1010, 1011, 1100, 1101, 1110 and 1111.
BCD Addition:
• Add corresponding bits of two BCD numbers.
• After Addition,
– If Result is <=9 & Carry=0, no correction is needed.
– Result is > 9 or Carry=1, correction is needed.
• then 610 (0110) is added and the resulting carry is added to the next group.
BCD Subtraction:
• Subtract corresponding bits of two BCD numbers.
• In Subtraction
– If no borrow from the next higher group then no correction is needed.
– If a borrow from the next group, correction is needed.
• then 610 (0110) is subtracted from the difference term of that group.
BCD Subtraction
Non weighted codes
• There are many nonweighted binary codes, two of which are
–Excess-3
–Gray Code
Excess-3 Code
• It is self-complementing code.
• It is obtained by adding 3(0011) to 4-bit pattern of the BCD CODE.
• It has six invalid states 0000, 0001, 0010, 1101, 1110 and 1111.
Gray Code
In a Gray code only one bit change between each pair of successive
code words So, it is called as Cyclic Code
It can be defined recursively using the following rules:
A 1-bit Gray code has two code words, 0 and 1.
0
1
1-bit Gray code:
0
1
 Example: For a 2-bit Gray code, n=1.
1-bit Gray code:
0
1
1
0
0
0
2-bit Gray code:
1
1
00
01
11
10
The first 2n code words of an (n+1)-bit gray code equal the code words
of an n-bit gray code, written in order with a leading 0 appended.
The last 2n code words of an (n+1)-bit Gray code equal the code words
of an n-bit gray code, but written in reverse order with a leading 1
appended.
 Example: For a 3-bit Gray code, n=2.
2-bit Gray code:
3-bit Gray code:
0
0
0
0
00
01
11
10
00
01
11
10
1
1
1
1
10
11
01
00
000
001
011
010
110
111
101
100
Gray Code:
Decimal Binary Gray Code
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
Decimal Binary Gray Code
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
Gray code is a reflective code or mirror image code.
Binary to Gray code conversion
• Binary-to-Gray code conversion
– The MSB in the Gray code is the same as corresponding MSB in the
binary number.
– Going from left to right, add or Ex-OR each adjacent pair of binary code
bits to get the next Gray code bit. Discard carries.
ex: convert 101102 to Gray code
1 + 0 + 1 + 1 + 0 binary
1 1 1 0 1 Gray
Gray to Binary code Conversion
• Gray-to-Binary Conversion
– The MSB in the binary code is the same as the corresponding bit in the Gray code.
– Add or Ex-OR each binary code bit generated to the Gray code bit in the next adjacent
position. Discard carries.
Ex: convert the Gray code word 11011 to binary
1 1 0 1 1 Gray
+ + + +
1 0 0 1 0 Binary
Complements
• Used to perform subtraction operation (Complement of the
subtrahend is added to the minued).
• It reduces hardware (only adding circuits are needed, Instead of
having separte digital circuits for addition and subtraction)
Complements
• There are two types of compliments for each number base system.
–r’s Complement
• r’s complement of N = (rn )-N.
–(r-1)’s Complement
• (r-1)’s complement of N = (rn -1)-N.
Binary(r=2) Decimal(r=10) Octal(r=8) Hexa(r=16)
2's Complement 10's Complement 8's Complement 16's Complement
1's Complement 9's Complement 7's Complement 15's Complement
1’s Complement
• 1’s complement of N = (2n -1)-N.
–If n=4  (2n -1)=10000 - 1 = 1111
• Subtract any 4-bit binary number from 1111.
• This is just inverting each bit.
• Example: 1’s compliment of 1011001
is 0100110
2’s complement
• The 2’s complement of N= 2n-N
= (2n-1)-N+1
= The 1’s complement of N+1
• Example:
–The 1’s complement of 6(0110) is 1001
–The 2’s complement of 6(0110) is 1010
Obtain the 1’s and 2’S complements of the following binary numbers :
(a)11101010 (b)01111110 (c)00000001 (d)10000000
1’s complements:
(a) 00010101 (b)10000001 (c)11111110 (d)01111111
2’s complement :
(a) 00010110 (b)10000010 (c)11111111 (d)10000000
1’s Complement Subtraction
There are Two cases:
• Subtraction of Smaller number from larger number.
• Subtraction of larger number from smaller number.
Subtraction of Smaller number from larger number
Procedure:
1. Determine the 1’s complement of the smaller number.
2. Add the 1’s complement to the larger number.
3. Remove the carry and add it to result.
Example: Subtract 101011 2 from 111001 2
Subtraction of Larger number from Smaller number
Procedure:
1. Determine the 1’s complement of the larger number.
2. Add the 1’s complement to the smaller number.
3. Answer is in 1’s complement form. Take 1’s complement form
and take negative sign
Example: Subtract 111001 2 from 101011 2
2’s Complement Subtraction
There are Two cases:
• Subtraction of Smaller number from larger number.
• Subtraction of larger number from smaller number.
Subtraction of Smaller number from larger number
Procedure:
1. Determine the 2’s complement of the smaller number.
2. Add the 2’s complement to the larger number.
3. Discard the Carry.
Example: Subtract 101011 2 from 111001 2
Subtraction of Larger number from Smaller number
Procedure:
1. Determine the 2’s complement of the larger number.
2. Add the 2’s complement to the smaller number.
3. Answer is in 2’s complement form. Take 2’s complement form
and take negative sign
Example: Subtract 111001 2 from 101011 2
Binary Addition, Subtraction
•Negative numbers must be in 2’s compliment form
•If the sum obtained after the addition is negative, it is in 2’s compliment form
Conclusions
Binary Codes
Weighted Codes(8-4-2-1,2-4-2-1,6-4-2- -3 codes)
Unweighted Codes( Excess-3,Cyclic,Gray codes)
Code conversions (Binary to Gray, Gray to Binary)
 1’s compliment and 2’s compliment
 Boolean addition and Subtraction

More Related Content

Similar to Unit-1 (DLD) Lecture 2.pptx

12.Representation of signed binary numbers. Binary codes - BCD code, Gray co...
12.Representation of signed binary numbers.  Binary codes - BCD code, Gray co...12.Representation of signed binary numbers.  Binary codes - BCD code, Gray co...
12.Representation of signed binary numbers. Binary codes - BCD code, Gray co...
JatinJatin30
 
3.Fixed-Floating Point.ppt
3.Fixed-Floating Point.ppt3.Fixed-Floating Point.ppt
3.Fixed-Floating Point.ppt
RavikumarR77
 

Similar to Unit-1 (DLD) Lecture 2.pptx (20)

W3 Chapter 2B Notes CCB1223 Digital Logic.pdf
W3 Chapter 2B Notes CCB1223 Digital Logic.pdfW3 Chapter 2B Notes CCB1223 Digital Logic.pdf
W3 Chapter 2B Notes CCB1223 Digital Logic.pdf
 
Codes r005
Codes  r005Codes  r005
Codes r005
 
12.Representation of signed binary numbers. Binary codes - BCD code, Gray co...
12.Representation of signed binary numbers.  Binary codes - BCD code, Gray co...12.Representation of signed binary numbers.  Binary codes - BCD code, Gray co...
12.Representation of signed binary numbers. Binary codes - BCD code, Gray co...
 
Chapter1b
Chapter1bChapter1b
Chapter1b
 
Number system and codes
Number system and codesNumber system and codes
Number system and codes
 
Lecture5 Chapter1- Binary Codes.pdf
Lecture5 Chapter1- Binary Codes.pdfLecture5 Chapter1- Binary Codes.pdf
Lecture5 Chapter1- Binary Codes.pdf
 
Digital Logic
Digital LogicDigital Logic
Digital Logic
 
ch2.pdf
ch2.pdfch2.pdf
ch2.pdf
 
digital logic circuits, digital component floting and fixed point
 digital logic circuits, digital component floting and fixed point digital logic circuits, digital component floting and fixed point
digital logic circuits, digital component floting and fixed point
 
DLD_PPT_0.pptx
DLD_PPT_0.pptxDLD_PPT_0.pptx
DLD_PPT_0.pptx
 
Number Systems.ppt
Number Systems.pptNumber Systems.ppt
Number Systems.ppt
 
Digital Logic BCA TU Chapter 2.2
Digital Logic BCA TU Chapter 2.2Digital Logic BCA TU Chapter 2.2
Digital Logic BCA TU Chapter 2.2
 
CDS Fundamentals of digital communication system UNIT 1 AND 2.pdf
CDS Fundamentals of digital communication system UNIT 1 AND 2.pdfCDS Fundamentals of digital communication system UNIT 1 AND 2.pdf
CDS Fundamentals of digital communication system UNIT 1 AND 2.pdf
 
Finite word length effects
Finite word length effectsFinite word length effects
Finite word length effects
 
Number system
Number systemNumber system
Number system
 
Chapter 10: Error Correction and Detection
Chapter 10: Error Correction and DetectionChapter 10: Error Correction and Detection
Chapter 10: Error Correction and Detection
 
Digital Electronics – Unit I.pdf
Digital Electronics – Unit I.pdfDigital Electronics – Unit I.pdf
Digital Electronics – Unit I.pdf
 
data representation
 data representation data representation
data representation
 
3.Fixed-Floating Point.ppt
3.Fixed-Floating Point.ppt3.Fixed-Floating Point.ppt
3.Fixed-Floating Point.ppt
 
digital logic circuits, digital component
digital logic circuits, digital componentdigital logic circuits, digital component
digital logic circuits, digital component
 

Recently uploaded

Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
kumaririma588
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
amitlee9823
 
Editorial design Magazine design project.pdf
Editorial design Magazine design project.pdfEditorial design Magazine design project.pdf
Editorial design Magazine design project.pdf
tbatkhuu1
 
Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard ...
Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard  ...Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard  ...
Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard ...
nirzagarg
 
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
instagramfab782445
 
Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
amitlee9823
 
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men 🔝dharamshala🔝 ...
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men  🔝dharamshala🔝  ...➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men  🔝dharamshala🔝  ...
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men 🔝dharamshala🔝 ...
amitlee9823
 
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
amitlee9823
 
👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...
👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...
👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...
karishmasinghjnh
 
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
amitlee9823
 

Recently uploaded (20)

Sector 104, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 104, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 104, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 104, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Hy...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Hy...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Hy...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Hy...
 
WhatsApp Chat: 📞 8617697112 Call Girl Baran is experienced
WhatsApp Chat: 📞 8617697112 Call Girl Baran is experiencedWhatsApp Chat: 📞 8617697112 Call Girl Baran is experienced
WhatsApp Chat: 📞 8617697112 Call Girl Baran is experienced
 
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...
UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...
UI:UX Design and Empowerment Strategies for Underprivileged Transgender Indiv...
 
💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...
💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...
💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...
 
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
 
Editorial design Magazine design project.pdf
Editorial design Magazine design project.pdfEditorial design Magazine design project.pdf
Editorial design Magazine design project.pdf
 
Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard ...
Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard  ...Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard  ...
Anamika Escorts Service Darbhanga ❣️ 7014168258 ❣️ High Cost Unlimited Hard ...
 
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
 
Hire 💕 8617697112 Meerut Call Girls Service Call Girls Agency
Hire 💕 8617697112 Meerut Call Girls Service Call Girls AgencyHire 💕 8617697112 Meerut Call Girls Service Call Girls Agency
Hire 💕 8617697112 Meerut Call Girls Service Call Girls Agency
 
Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
Call Girls Basavanagudi Just Call 👗 7737669865 👗 Top Class Call Girl Service ...
 
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...
 
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
 
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men 🔝dharamshala🔝 ...
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men  🔝dharamshala🔝  ...➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men  🔝dharamshala🔝  ...
➥🔝 7737669865 🔝▻ dharamshala Call-girls in Women Seeking Men 🔝dharamshala🔝 ...
 
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
Whitefield Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Ba...
 
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best ServiceHigh Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
 
👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...
👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...
👉 Call Girls Service Amritsar 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Agen...
 
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men  🔝dehradun🔝   Escor...
➥🔝 7737669865 🔝▻ dehradun Call-girls in Women Seeking Men 🔝dehradun🔝 Escor...
 

Unit-1 (DLD) Lecture 2.pptx

  • 1. Binary Codes Binary codes are of two types:  Weighted Codes.  Non weighted or Unweighted Codes.
  • 2. Weighted codes • Each binary bit is assigned a “Decimal weight”. 8 4 2 1 Ex: (0 1 0 1)2= 510 • Each group of 4 bits, the sum of the weights of those binary bits whose value is 1 is equal to the decimal number which they represent. Weighted Codes • 1.Positive Weighted Code 2.Negative Weighted Code • Examples: – 8421 --642-3 – 2421 --84-2-1 – 5211 – 5421
  • 4. BCD(Binary Coded Decimal) CODE • It is a weighted code. • It is a special code used to represent single decimal digit. • Each decimal digit from 0 to 9 is coded by a 4-bit binary number. • It has six invalid states 1010, 1011, 1100, 1101, 1110 and 1111.
  • 5. BCD Addition: • Add corresponding bits of two BCD numbers. • After Addition, – If Result is <=9 & Carry=0, no correction is needed. – Result is > 9 or Carry=1, correction is needed. • then 610 (0110) is added and the resulting carry is added to the next group.
  • 6.
  • 7. BCD Subtraction: • Subtract corresponding bits of two BCD numbers. • In Subtraction – If no borrow from the next higher group then no correction is needed. – If a borrow from the next group, correction is needed. • then 610 (0110) is subtracted from the difference term of that group.
  • 9. Non weighted codes • There are many nonweighted binary codes, two of which are –Excess-3 –Gray Code
  • 10. Excess-3 Code • It is self-complementing code. • It is obtained by adding 3(0011) to 4-bit pattern of the BCD CODE. • It has six invalid states 0000, 0001, 0010, 1101, 1110 and 1111.
  • 11. Gray Code In a Gray code only one bit change between each pair of successive code words So, it is called as Cyclic Code It can be defined recursively using the following rules: A 1-bit Gray code has two code words, 0 and 1. 0 1 1-bit Gray code:
  • 12. 0 1  Example: For a 2-bit Gray code, n=1. 1-bit Gray code: 0 1 1 0 0 0 2-bit Gray code: 1 1 00 01 11 10 The first 2n code words of an (n+1)-bit gray code equal the code words of an n-bit gray code, written in order with a leading 0 appended. The last 2n code words of an (n+1)-bit Gray code equal the code words of an n-bit gray code, but written in reverse order with a leading 1 appended.
  • 13.  Example: For a 3-bit Gray code, n=2. 2-bit Gray code: 3-bit Gray code: 0 0 0 0 00 01 11 10 00 01 11 10 1 1 1 1 10 11 01 00 000 001 011 010 110 111 101 100
  • 14. Gray Code: Decimal Binary Gray Code 0 0000 0000 1 0001 0001 2 0010 0011 3 0011 0010 4 0100 0110 5 0101 0111 6 0110 0101 7 0111 0100 Decimal Binary Gray Code 8 1000 1100 9 1001 1101 10 1010 1111 11 1011 1110 12 1100 1010 13 1101 1011 14 1110 1001 15 1111 1000 Gray code is a reflective code or mirror image code.
  • 15. Binary to Gray code conversion • Binary-to-Gray code conversion – The MSB in the Gray code is the same as corresponding MSB in the binary number. – Going from left to right, add or Ex-OR each adjacent pair of binary code bits to get the next Gray code bit. Discard carries. ex: convert 101102 to Gray code 1 + 0 + 1 + 1 + 0 binary 1 1 1 0 1 Gray
  • 16. Gray to Binary code Conversion • Gray-to-Binary Conversion – The MSB in the binary code is the same as the corresponding bit in the Gray code. – Add or Ex-OR each binary code bit generated to the Gray code bit in the next adjacent position. Discard carries. Ex: convert the Gray code word 11011 to binary 1 1 0 1 1 Gray + + + + 1 0 0 1 0 Binary
  • 17. Complements • Used to perform subtraction operation (Complement of the subtrahend is added to the minued). • It reduces hardware (only adding circuits are needed, Instead of having separte digital circuits for addition and subtraction)
  • 18. Complements • There are two types of compliments for each number base system. –r’s Complement • r’s complement of N = (rn )-N. –(r-1)’s Complement • (r-1)’s complement of N = (rn -1)-N. Binary(r=2) Decimal(r=10) Octal(r=8) Hexa(r=16) 2's Complement 10's Complement 8's Complement 16's Complement 1's Complement 9's Complement 7's Complement 15's Complement
  • 19. 1’s Complement • 1’s complement of N = (2n -1)-N. –If n=4  (2n -1)=10000 - 1 = 1111 • Subtract any 4-bit binary number from 1111. • This is just inverting each bit. • Example: 1’s compliment of 1011001 is 0100110
  • 20. 2’s complement • The 2’s complement of N= 2n-N = (2n-1)-N+1 = The 1’s complement of N+1 • Example: –The 1’s complement of 6(0110) is 1001 –The 2’s complement of 6(0110) is 1010
  • 21. Obtain the 1’s and 2’S complements of the following binary numbers : (a)11101010 (b)01111110 (c)00000001 (d)10000000 1’s complements: (a) 00010101 (b)10000001 (c)11111110 (d)01111111 2’s complement : (a) 00010110 (b)10000010 (c)11111111 (d)10000000
  • 22. 1’s Complement Subtraction There are Two cases: • Subtraction of Smaller number from larger number. • Subtraction of larger number from smaller number.
  • 23. Subtraction of Smaller number from larger number Procedure: 1. Determine the 1’s complement of the smaller number. 2. Add the 1’s complement to the larger number. 3. Remove the carry and add it to result. Example: Subtract 101011 2 from 111001 2
  • 24. Subtraction of Larger number from Smaller number Procedure: 1. Determine the 1’s complement of the larger number. 2. Add the 1’s complement to the smaller number. 3. Answer is in 1’s complement form. Take 1’s complement form and take negative sign Example: Subtract 111001 2 from 101011 2
  • 25. 2’s Complement Subtraction There are Two cases: • Subtraction of Smaller number from larger number. • Subtraction of larger number from smaller number.
  • 26. Subtraction of Smaller number from larger number Procedure: 1. Determine the 2’s complement of the smaller number. 2. Add the 2’s complement to the larger number. 3. Discard the Carry. Example: Subtract 101011 2 from 111001 2
  • 27. Subtraction of Larger number from Smaller number Procedure: 1. Determine the 2’s complement of the larger number. 2. Add the 2’s complement to the smaller number. 3. Answer is in 2’s complement form. Take 2’s complement form and take negative sign Example: Subtract 111001 2 from 101011 2
  • 28.
  • 29.
  • 30. Binary Addition, Subtraction •Negative numbers must be in 2’s compliment form •If the sum obtained after the addition is negative, it is in 2’s compliment form
  • 31. Conclusions Binary Codes Weighted Codes(8-4-2-1,2-4-2-1,6-4-2- -3 codes) Unweighted Codes( Excess-3,Cyclic,Gray codes) Code conversions (Binary to Gray, Gray to Binary)  1’s compliment and 2’s compliment  Boolean addition and Subtraction