SlideShare a Scribd company logo
1 of 74
Download to read offline
1
Digital Electronics
Binary Coded Decimal (BCD)
Prof. Prasenjit Kumar Das
Dept. of CST/CSIT, UEM Kolkata
Email : prasenjit.das@uem.edu.in
2
BCD, ASCII, EBCDIC, Gray codes
and their conversions
3
Binary Coded Decimal - BCD
In computing and electronic systems, binary-coded decimal (BCD) is a class of
binary encodings of decimal numbers where each digit is represented by a fixed
number of bits
BCD was commonly used for displaying alpha-numeric in the past but in
modern-day BCD is still used with real-time clocks or RTC chips to keep track of
wall-clock time and it's becoming more common for embedded microprocessors to
include an RTC.
It's very common for RTCs to store the time in BCD format
4
BCD Vs Binary
 Both binary-coded decimal (BCD) and binary numbers are used in
many digital applications.
 Both have their advantages and disadvantages.
 BCD is commonly used when decimal numbers must be represented in
hardware, as each 4-bit BCD number maps directly to a decimal
number.
 Binary is more efficient for arithmetic, memory storage, and
transmitting information, but is less human-readable.
5
Binary Coded Decimal - BCD
 Each single decimal digit represented in binary Coded to 4-bit binary
number
 Radix/Base for decimal number system = 10 So, 10 values possible in
each digit: 0 to 9
 In binary, Radix/Base is = 2 So, only 2 values possible in each digit: 0
and 1
6
For example,
 143 is a decimal number 1, 4 and 3 are the separate digits
 Each of the digits 1, 4 and 3, needs to be converted (coded) to binary
separately
 Each digit will be represented as 4 digit binary number
7
 BCD uses ‘positional weights’
 Each decimal digit, in the 4-bit representation, is expressed
in terms of the positional weights
 The ‘positional weights’ used in BCD are:
8-4-2-1
8
 Each bit – binary digit can contain either
0 or 1
 2 values possible in each bit –
expressed in power of 2
 8 – 4 – 2 – 1 is better
understood as
23
– 22
– 21
– 20
 Here, 20 represents the LSB and 23 represents the MSB
for the 4-bit binary code
9
Note
 We use 4 bits in BCD, so 24
= 16 values can be represented
 Out of 16, we use only 10 decimal digits, 0 to 9
 Rest of the values 10 to 15 are invalid,
as they are decimal numbers, not digits
 Note: BCD is the same as 4-bit Binary representation for decimal
digits 0 to 9
10
Representing Decimal Digit 0
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
0 0 0 0 0 0 0 0 0
Note: the Decimal Digit is expressed in terms of positional weights,
place 1 in case of the positional weights that are required,
for all others place 0
11
Representing Decimal Digit 1
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
1 0 0 0 1 0 0 0 1
Note: the Decimal Digit is expressed in terms of positional weights,
place 1 in case of the positional weights that are required,
for all others place 0
12
Representing Decimal Digit 2
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
2 0 0 1 0 0 0 1 0
Note: the Decimal Digit is expressed in terms of positional weights,
place 1 in case of the positional weights that are required,
for all others place 0
13
Representing Decimal Digit 3
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
3 0 0 1 1 0 0 1 1
Note: the Decimal Digit is expressed in terms of positional weights,
place 1 in case of the positional weights that are required,
for all others place 0
14
Representing Decimal Digit 4
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
4 0 1 0 0 0 1 0 0
Note: the Decimal Digit is expressed in terms of positional weights,
place 1 in case of the positional weights that are required,
for all others place 0
15
Representing Decimal Digit 5
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
5 0 1 0 1 0 1 0 1
Note: the Decimal Digit is expressed in terms of positional weights,
place 1 in case of the positional weights that are required,
for all others place 0
16
Representing Decimal Digit 6
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
6 0 1 1 0 0 1 1 0
Note: the Decimal Digit is expressed in terms of positional weights,
place 1 in case of the positional weights that are required,
for all others place 0
17
Representing Decimal Digit 7
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
7 0 1 1 1 0 1 1 1
Note: the Decimal Digit is expressed in terms of positional weights,
place 1 in case of the positional weights that are required,
for all others place 0
18
Representing Decimal Digit 8
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
8 1 0 0 0 1 0 0 0
Note: the Decimal Digit is expressed in terms of positional weights,
place 1 in case of the positional weights that are required,
for all others place 0
19
Representing Decimal Digit 9
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
9 1 0 0 1 1 0 0 1
Note: the Decimal Digit is expressed in terms of positional weights,
place 1 in case of the positional weights that are required,
for all others place 0
20
Summary Chart – BCD for Decimal
Digits
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 1
2 0 0 1 0 0 0 1 0
3 0 0 1 1 0 0 1 1
4 0 1 0 0 0 1 0 0
5 0 1 0 1 0 1 0 1
6 0 1 1 0 0 1 1 0
7 0 1 1 1 0 1 1 1
8 1 0 0 0 1 0 0 0
9 1 0 0 1 1 0 0 1
21
2 types of Conversions
Decimal Number
BCD
BCD
Decimal Number
22
Decimal Number to BCD Example 1
Q) Find BCD for Decimal Number 13
●(13)10 is a decimal number, not digit
●2 decimal digits in (13)10, 1 and 3
●First, we need to convert each digit to corresponding BCD value
●Then we place the BCD values together in proper order to get the
final BCD representation
23
Finding individual BCD values
●BCD for Decimal Digit 1 = 0001
●
●BCD for Decimal Digit 3 = 0011
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
1 0 0 0 1 0 0 0 1
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
3 0 0 1 1 0 0 1 1
24
Final BCD of Decimal Number 13
●Therefore, BCD of (13)10 is:
●0001 0011
BCD of 1 BCD of 3
25
Decimal Number to BCD Example 2
●(174)10 is a decimal number, not digit
●3 decimal digits in (174)10 - 1, 7 and 4
●First, we need to convert each digit to
corresponding BCD value
●Then we place the BCD values together in
proper order to get the final BCD
representation
26
Finding individual BCD values
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
1 0 0 0 1 0 0 0 1
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
7 0 1 1 1 0 1 1 1
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
4 0 1 0 0 0 1 0 0
BCD for Decimal Digit 1 = 0001
BCD for Decimal Digit 7 = 0111
BCD for Decimal Digit 4 = 0100
27
Final BCD of Decimal Number 174
●Therefore, BCD of (174)10 is:
●0001 0111 0100
BCD of 1 BCD of 7 BCD of 4
28
BCD to Decimal Number
Conversion
●The BCD code for each decimal digit is of 4-
bit length
●So for any given BCD code,
●Starting from the right,
find the 4-bit groups in the given BCD
●Using the conversion table, determine the
decimal equivalent for each BCD code
●Place all decimal digits together to find
the final decimal number
29
BCD to Decimal Number Example
1
q. Find Decimal Number for BCD 00010101
●Starting with the LSB, make group of 4-bits
●0001 0101
●
●So, we find 2 groups, means 2 decimal digits
●Look up the corresponding decimal digit for
each BCD code in the conversion table
30
Finding the corresponding
decimal digits
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
1 0 0 0 1 0 0 0 1
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
5 0 1 0 1 0 1 0 1
So, decimal digit for BCD 0001 is 1
So, decimal digit for BCD 0101 is 5
31
Final Decimal Number
●Therefore, Decimal Number for BCD
00010101 = (15)10
●
0001 0101
(1 5)10
32
BCD to Decimal Number Example 2
●In many cases, the BCD code may not be
easily seperated in groups of 4-bits
●
q. Find Decimal Number for BCD 100001
●Here, the given BCD is of length 6 !
33
Solution
●In this case, the grouping will be:
10 0001
●Clearly, the first group is not a valid BCD code
●To make it valid, add required number of 0s at the
left of the number to change it to 4-bits
●So, the groups now become:
0010 0001
●2 zeroes (highlighted in red) are added before the
MSB to make make 4-bit BCD
34
Finding the corresponding
decimal digits
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
2 0 0 1 0 0 0 1 0
Decimal Digit Binary Coded Decimal
8 4 2 1 Final
1 0 0 0 1 0 0 0 1
So, decimal digit for BCD 0001 is 2
So, decimal digit for BCD 0001 is 1
35
Final Decimal Number
●Therefore, Decimal Number for BCD
00100001 = (21)10
●
0010 0001
(2 1)10
36
●1 3 2 6 – convert to BCD
0001 0011 0010 0110
●11101 – convert to Decimal
0001 1101
37
BCD, ASCII, EBCDIC, Gray codes
and their conversions
38
ASCII Code
 American Standard Code for Information
Interchange – ASCII
 127 different characters represented
 127 = 27 – 1, so ASCII is a 7-bit code
 Codes are numbered from 0 to 126
39
40
Some important ASCII codes
Characters ASCII Code
0 to 9 48 to 57
(A to Z) 65 to 90
(a to z) 97 to 122
For alphabets,
Think of index starting wit
A 0 65
B 1 65+1
C 2 65+2
D 3 65+3
.........
J 9 65+9=74
a 0 97
b 1 98=97+1
c 2 99=97+2
d 3 100
...............
j 9 97+9=106
41
Binary to ASCII conversion
●Starting from the right (LSB),
Group every 7 bits together
●For each group of 7 bits,
Determine the corresponding decimal
value
●Use ASCII table to find the ASCII code
for each group
42
Binary to ASCII conversion
Example 1
q. Convert 10010110110001 to ASCII
●First, we make 7-bit groups, starting with
the LSB
●1001011 0110001
●Next, we convert each 7-bit binary to
decimal number
43
In decimal,
●1001011
6 5 4 3 2 1 0
●= 1x20 + 1x21 + 0x22 + 1x23 + 0x24 + 0x25 + 1x26
●= 1 + 2 + 8 + 64 = 75
●0110001
6 5 4 3 2 1 0
●= 1x20 + 0x21 + 0x22 + 0x23 + 1x24 + 1x25 + 0x26
●= 1 + 16 + 32 = 49
●
44
●Finally, we find the corresponding
ASCII values
75 in ASCII = K
49 in ASCII = 1
●So, 10010110110001 in ASCII is K1
45
ASCII to Binary Conversion
Example 1
q. Convert Mp4 in ASCII to Binary
●First, find the corresponding decimal
numbers for each ASCII character
●M p 4
77 112 52
46
●Next, convert each decimal number to binary
●77 in binary:
2|77 – 1
2|38 – 0
2|19 – 1
2| 9 – 1
2| 4 – 0
2| 2 – 0
1
●112 in binary:
2|112 – 0
2|56 – 0
2|28 – 0
2|14 – 0
2| 7 – 1
2| 3 – 1
1
●52 in binary:
2|52 – 0
2|26 – 0
2|13 – 1
2| 6 – 0
2| 3 – 1
1
47
●Next, each of the binary numbers will placed in order
of their corresponding decimal numbers
●So,
77 112
52
1001101 1110000
0110100
●Since we are converting ASCII to binary, all binary
representations have to be of 7-bits
●Here, binary for 52 is of 6 bits, so we add 0 at LSB
48
●So, each binary has to be converted to
7-bit form by adding 0s to the LSB as
required
●Finally, the Binary form of ASCII Mp4
is =
●
(1001101 1110000 0110100)2
49
BCD, ASCII, EBCDIC, Gray codes
and their conversions
50
EBCDIC Code
●Extended Binary Coded Decimal Interchange
Code
●8-bit representation in binary form
●Mainly used in IBM Mainframe machines
●Extension of Binary Coded Decimal form
●Makes use of fixed, 4-bit ‘Zone’ bits
with
4-bit binary representation of digits etc.
51
EBCDIC Code equivalent for
Digits 0-9
Character EBCDIC Code
Zone Digit
0 1111 0000
1 1111 0001
2 1111 0010
3 1111 0011
4 1111 0100
5 1111 0101
6 1111 0110
7 1111 0111
8 1111 1000
9 1111 1001
●4-bit Zone bits for digits is 1111
●The 4-bit binary representation is same as BCD codes
52
EBCDIC Code equivalent for
Alphabets
Character EBCDIC
Zone Digits
A 1100 0001
B 1100 0010
C 1100 0011
D 1100 0100
E 1100 0101
F 1100 0110
G 1100 0111
H 1100 1000
I 1100 1001
●The 26 alphabets are divided in 3 groups
A to I (9),
J to R (9), and
S to Z (8)
●Each group has separate 4-bit Zone bits:
A to I: 1100
●For each group, the digit value goes from 1 to 9, and
●corresponding 4-bit binary is used
53
EBCDIC Code equivalent for
Alphabets
Character EBCDIC
Zone Digit
J 1101 0001
K 1101 0010
L 1101 0011
M 1101 0100
N 1101 0101
O 1101 0110
P 1101 0111
Q 1101 1000
R 1101 1001
●For this group, the 4-bit Zone bits are
J to R: 1101
●The digit value goes from 1 to 9, and so the same corr
54
EBCDIC Code equivalent for
Alphabets
Character EBCDIC
Zone Digit
S 1110 0010
T 1110 0011
U 1110 0100
V 1110 0101
W 1110 0110
X 1110 0111
Y 1110 1000
Z 1110 1001
●For this group, the 4-bit Zone bits are
S to Z: 1110
●The digit value goes from 2 to 9, and so the same
● corresponding 4-bit binary is used
55
Decimal Number to EBCDIC Example
1
q. Convert 425 to EBCDIC
●First, determine the zone bits – here it is
1111 (for digits)
●Next, find the BCD of each decimal digit:
●4 5 2
0100 0010 0101
56
●To the BCDs, append the Zone bits at LSB
4 2
5
11110100 11110010
11110101
●Bring the 8-bit codes together in order to get
the final EBCDIC representation:
●11110100 11110010 11110101
57
EBCDIC to Character Example 1
q. Convert the following EBCDIC to
Decimal:
1111100111111000
●First, make groups of 8-bits each
starting from the right
11111001 11111000
58
●The first 4-bits of each group
represents Zone bits,use it to identify
the type of data
●Here Zone bits = 1111, so we have digits
●For each group, starting with the right,
extract the 4 digit bits and find their
corresponding decimal value
●11111001 11111000
1001 1000
59
In decimal,
1001
3 2 1 0
= 1x20 +1x23 = 9
1000
3 2 1 0
= 1x23 = 8
So, placing the decimal digits in order, the
converted value of given EBCDIC code = 98
60
BCD, ASCII, EBCDIC, Gray codes
and their conversions
61
Gray Code
●Named after scientist Frank Gray
●Called ‘Reflected Binary code’
●Expressions for sequential numbers differ
only by 1 bit
●So, binary expressions are converted to
Gray Code to minimize switching operations
●Also called ‘Unit Distance Code’, ‘Cyclic
Code’
62
Binary to Gray Code conversion
●Take the MSB – this is the MSB for Gray
Code
●Add MSB to next bit of Binary, keep the
sum and ignore carry (XOR) – the sum is
the 2nd bit after MSB in Gray Code
●Keep shifting bit by bit towards right,
and repeat the above two steps to obtain
the complete Gray Code
63
Generalized Rule
●If a binary number b3b2b1b0 is to be
converted to Gray Code g3g2g1g0,
●g3 = b3,
●g2=b3⊕b2
●g1=b2⊕b1
●g0=b1⊕b0
64
Example of Binary to Gray Code
convertion
q. Convert 1101 to Gray Code
Step 1:
●MSB of 1101 is 1
●So, MSB of Gray
Code is set as 1
Binary: 1 1 0 1
Gray Code:1
65
Example of Binary to Gray Code
convertion
Step 2:
●Add MSB (1) to ne
●Set the sum (0) a
●Ignore the carry
Binary: 1 1 0 1
+
Gray Code: 1 0
66
Example of Binary to Gray Code
convertion
Step 3:
●Add succeeding bi
●Set the sum (1) a
●Ignore the carry
Binary: 1 1 0 1
+
Gray Code: 1 0 1
67
Example of Binary to Gray Code
conversion
Step 4:
●Add succeeding bi
●Set the sum (1) a
●Ignore the carry
Binary: 1 1 0 1
+
Gray Code: 1 0 1 1
68
Gray Code to Binary conversion
●Take the MSB – this is the MSB for Gray
Code
●Add MSB to next bit of Gray Code, keep
the sum and ignore carry (XOR) – the sum
is the 2nd bit after MSB
●Keep shifting bit by bit towards right,
and repeat the above two steps to obtain
the complete Gray Code
69
Generalized Rule
●If a Gray Code g3g2g1g0 is to be
converted to binary number b3b2b1b0,
●b3 = g3,
●b2=b3⊕g2
●b1=b2⊕g1
●b0=b1⊕g0
70
Example of Gray Code to Binary
conversion
q. Convert 1011 to Binary
Step 1:
●MSB of 1011 is 1
●So, MSB of Binary
Gray Code: 1 0 1 1
Binary: 1
71
Example of Gray Code to Binary
conversion
Step 2:
●XOR the MSB (1) t
●Set the result (1
Gray Code: 1 0 1 1
⊕
Binary: 1 1
72
Example of Binary to Gray Code
convertion
Step 3:
●XOR the succeesin
●Set the result (0
Gray Code: 1 0 1 1
⊕
Binary: 1 1 0
73
Example of Binary to Gray Code
conversion
Step 4:
●XOR the succeesin
●Set the result (1
Gray Code: 1 0 1 1
⊕
Binary: 1 1 0 1
74
Thank You

More Related Content

Similar to BCD and ASCII Code Conversions

Similar to BCD and ASCII Code Conversions (20)

IARE_DLD_PPT_0.pdf
IARE_DLD_PPT_0.pdfIARE_DLD_PPT_0.pdf
IARE_DLD_PPT_0.pdf
 
Lecture 5 binary_codes
Lecture 5 binary_codesLecture 5 binary_codes
Lecture 5 binary_codes
 
Digital Electronics- Number systems & codes
Digital Electronics- Number systems & codes Digital Electronics- Number systems & codes
Digital Electronics- Number systems & codes
 
Codes r005
Codes  r005Codes  r005
Codes r005
 
BCD,GRAY and EXCESS 3 codes
BCD,GRAY and EXCESS 3 codesBCD,GRAY and EXCESS 3 codes
BCD,GRAY and EXCESS 3 codes
 
9pL7F2E8XI0alXYT280.pptx
9pL7F2E8XI0alXYT280.pptx9pL7F2E8XI0alXYT280.pptx
9pL7F2E8XI0alXYT280.pptx
 
Number codes students
Number codes studentsNumber codes students
Number codes students
 
Chapter02.pdf
Chapter02.pdfChapter02.pdf
Chapter02.pdf
 
Lecture_Computer_Codes.ppt
Lecture_Computer_Codes.pptLecture_Computer_Codes.ppt
Lecture_Computer_Codes.ppt
 
What is bcd number system
What is bcd number systemWhat is bcd number system
What is bcd number system
 
BCD to binary code converter
BCD to binary code converterBCD to binary code converter
BCD to binary code converter
 
Digital Logic Rcs
Digital Logic RcsDigital Logic Rcs
Digital Logic Rcs
 
Binary codes
Binary codesBinary codes
Binary codes
 
binarycodes.pdf
binarycodes.pdfbinarycodes.pdf
binarycodes.pdf
 
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
 
Bcd
BcdBcd
Bcd
 
Chapter 5: Cominational Logic with MSI and LSI
Chapter 5: Cominational Logic with MSI and LSIChapter 5: Cominational Logic with MSI and LSI
Chapter 5: Cominational Logic with MSI and LSI
 
Unit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.ppt
Unit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.pptUnit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.ppt
Unit1_Part2-Machine_Instructions_Programs_7_9_2018_3pm.ppt
 
Csc 2313 (lecture 3)
Csc 2313 (lecture 3)Csc 2313 (lecture 3)
Csc 2313 (lecture 3)
 
Csc 2313 (lecture 3)
Csc 2313 (lecture 3)Csc 2313 (lecture 3)
Csc 2313 (lecture 3)
 

Recently uploaded

Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 

Recently uploaded (20)

Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 

BCD and ASCII Code Conversions

  • 1. 1 Digital Electronics Binary Coded Decimal (BCD) Prof. Prasenjit Kumar Das Dept. of CST/CSIT, UEM Kolkata Email : prasenjit.das@uem.edu.in
  • 2. 2 BCD, ASCII, EBCDIC, Gray codes and their conversions
  • 3. 3 Binary Coded Decimal - BCD In computing and electronic systems, binary-coded decimal (BCD) is a class of binary encodings of decimal numbers where each digit is represented by a fixed number of bits BCD was commonly used for displaying alpha-numeric in the past but in modern-day BCD is still used with real-time clocks or RTC chips to keep track of wall-clock time and it's becoming more common for embedded microprocessors to include an RTC. It's very common for RTCs to store the time in BCD format
  • 4. 4 BCD Vs Binary  Both binary-coded decimal (BCD) and binary numbers are used in many digital applications.  Both have their advantages and disadvantages.  BCD is commonly used when decimal numbers must be represented in hardware, as each 4-bit BCD number maps directly to a decimal number.  Binary is more efficient for arithmetic, memory storage, and transmitting information, but is less human-readable.
  • 5. 5 Binary Coded Decimal - BCD  Each single decimal digit represented in binary Coded to 4-bit binary number  Radix/Base for decimal number system = 10 So, 10 values possible in each digit: 0 to 9  In binary, Radix/Base is = 2 So, only 2 values possible in each digit: 0 and 1
  • 6. 6 For example,  143 is a decimal number 1, 4 and 3 are the separate digits  Each of the digits 1, 4 and 3, needs to be converted (coded) to binary separately  Each digit will be represented as 4 digit binary number
  • 7. 7  BCD uses ‘positional weights’  Each decimal digit, in the 4-bit representation, is expressed in terms of the positional weights  The ‘positional weights’ used in BCD are: 8-4-2-1
  • 8. 8  Each bit – binary digit can contain either 0 or 1  2 values possible in each bit – expressed in power of 2  8 – 4 – 2 – 1 is better understood as 23 – 22 – 21 – 20  Here, 20 represents the LSB and 23 represents the MSB for the 4-bit binary code
  • 9. 9 Note  We use 4 bits in BCD, so 24 = 16 values can be represented  Out of 16, we use only 10 decimal digits, 0 to 9  Rest of the values 10 to 15 are invalid, as they are decimal numbers, not digits  Note: BCD is the same as 4-bit Binary representation for decimal digits 0 to 9
  • 10. 10 Representing Decimal Digit 0 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 0 0 0 0 0 0 0 0 0 Note: the Decimal Digit is expressed in terms of positional weights, place 1 in case of the positional weights that are required, for all others place 0
  • 11. 11 Representing Decimal Digit 1 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 1 0 0 0 1 0 0 0 1 Note: the Decimal Digit is expressed in terms of positional weights, place 1 in case of the positional weights that are required, for all others place 0
  • 12. 12 Representing Decimal Digit 2 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 2 0 0 1 0 0 0 1 0 Note: the Decimal Digit is expressed in terms of positional weights, place 1 in case of the positional weights that are required, for all others place 0
  • 13. 13 Representing Decimal Digit 3 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 3 0 0 1 1 0 0 1 1 Note: the Decimal Digit is expressed in terms of positional weights, place 1 in case of the positional weights that are required, for all others place 0
  • 14. 14 Representing Decimal Digit 4 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 4 0 1 0 0 0 1 0 0 Note: the Decimal Digit is expressed in terms of positional weights, place 1 in case of the positional weights that are required, for all others place 0
  • 15. 15 Representing Decimal Digit 5 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 5 0 1 0 1 0 1 0 1 Note: the Decimal Digit is expressed in terms of positional weights, place 1 in case of the positional weights that are required, for all others place 0
  • 16. 16 Representing Decimal Digit 6 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 6 0 1 1 0 0 1 1 0 Note: the Decimal Digit is expressed in terms of positional weights, place 1 in case of the positional weights that are required, for all others place 0
  • 17. 17 Representing Decimal Digit 7 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 7 0 1 1 1 0 1 1 1 Note: the Decimal Digit is expressed in terms of positional weights, place 1 in case of the positional weights that are required, for all others place 0
  • 18. 18 Representing Decimal Digit 8 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 8 1 0 0 0 1 0 0 0 Note: the Decimal Digit is expressed in terms of positional weights, place 1 in case of the positional weights that are required, for all others place 0
  • 19. 19 Representing Decimal Digit 9 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 9 1 0 0 1 1 0 0 1 Note: the Decimal Digit is expressed in terms of positional weights, place 1 in case of the positional weights that are required, for all others place 0
  • 20. 20 Summary Chart – BCD for Decimal Digits Decimal Digit Binary Coded Decimal 8 4 2 1 Final 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 2 0 0 1 0 0 0 1 0 3 0 0 1 1 0 0 1 1 4 0 1 0 0 0 1 0 0 5 0 1 0 1 0 1 0 1 6 0 1 1 0 0 1 1 0 7 0 1 1 1 0 1 1 1 8 1 0 0 0 1 0 0 0 9 1 0 0 1 1 0 0 1
  • 21. 21 2 types of Conversions Decimal Number BCD BCD Decimal Number
  • 22. 22 Decimal Number to BCD Example 1 Q) Find BCD for Decimal Number 13 ●(13)10 is a decimal number, not digit ●2 decimal digits in (13)10, 1 and 3 ●First, we need to convert each digit to corresponding BCD value ●Then we place the BCD values together in proper order to get the final BCD representation
  • 23. 23 Finding individual BCD values ●BCD for Decimal Digit 1 = 0001 ● ●BCD for Decimal Digit 3 = 0011 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 1 0 0 0 1 0 0 0 1 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 3 0 0 1 1 0 0 1 1
  • 24. 24 Final BCD of Decimal Number 13 ●Therefore, BCD of (13)10 is: ●0001 0011 BCD of 1 BCD of 3
  • 25. 25 Decimal Number to BCD Example 2 ●(174)10 is a decimal number, not digit ●3 decimal digits in (174)10 - 1, 7 and 4 ●First, we need to convert each digit to corresponding BCD value ●Then we place the BCD values together in proper order to get the final BCD representation
  • 26. 26 Finding individual BCD values Decimal Digit Binary Coded Decimal 8 4 2 1 Final 1 0 0 0 1 0 0 0 1 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 7 0 1 1 1 0 1 1 1 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 4 0 1 0 0 0 1 0 0 BCD for Decimal Digit 1 = 0001 BCD for Decimal Digit 7 = 0111 BCD for Decimal Digit 4 = 0100
  • 27. 27 Final BCD of Decimal Number 174 ●Therefore, BCD of (174)10 is: ●0001 0111 0100 BCD of 1 BCD of 7 BCD of 4
  • 28. 28 BCD to Decimal Number Conversion ●The BCD code for each decimal digit is of 4- bit length ●So for any given BCD code, ●Starting from the right, find the 4-bit groups in the given BCD ●Using the conversion table, determine the decimal equivalent for each BCD code ●Place all decimal digits together to find the final decimal number
  • 29. 29 BCD to Decimal Number Example 1 q. Find Decimal Number for BCD 00010101 ●Starting with the LSB, make group of 4-bits ●0001 0101 ● ●So, we find 2 groups, means 2 decimal digits ●Look up the corresponding decimal digit for each BCD code in the conversion table
  • 30. 30 Finding the corresponding decimal digits Decimal Digit Binary Coded Decimal 8 4 2 1 Final 1 0 0 0 1 0 0 0 1 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 5 0 1 0 1 0 1 0 1 So, decimal digit for BCD 0001 is 1 So, decimal digit for BCD 0101 is 5
  • 31. 31 Final Decimal Number ●Therefore, Decimal Number for BCD 00010101 = (15)10 ● 0001 0101 (1 5)10
  • 32. 32 BCD to Decimal Number Example 2 ●In many cases, the BCD code may not be easily seperated in groups of 4-bits ● q. Find Decimal Number for BCD 100001 ●Here, the given BCD is of length 6 !
  • 33. 33 Solution ●In this case, the grouping will be: 10 0001 ●Clearly, the first group is not a valid BCD code ●To make it valid, add required number of 0s at the left of the number to change it to 4-bits ●So, the groups now become: 0010 0001 ●2 zeroes (highlighted in red) are added before the MSB to make make 4-bit BCD
  • 34. 34 Finding the corresponding decimal digits Decimal Digit Binary Coded Decimal 8 4 2 1 Final 2 0 0 1 0 0 0 1 0 Decimal Digit Binary Coded Decimal 8 4 2 1 Final 1 0 0 0 1 0 0 0 1 So, decimal digit for BCD 0001 is 2 So, decimal digit for BCD 0001 is 1
  • 35. 35 Final Decimal Number ●Therefore, Decimal Number for BCD 00100001 = (21)10 ● 0010 0001 (2 1)10
  • 36. 36 ●1 3 2 6 – convert to BCD 0001 0011 0010 0110 ●11101 – convert to Decimal 0001 1101
  • 37. 37 BCD, ASCII, EBCDIC, Gray codes and their conversions
  • 38. 38 ASCII Code  American Standard Code for Information Interchange – ASCII  127 different characters represented  127 = 27 – 1, so ASCII is a 7-bit code  Codes are numbered from 0 to 126
  • 39. 39
  • 40. 40 Some important ASCII codes Characters ASCII Code 0 to 9 48 to 57 (A to Z) 65 to 90 (a to z) 97 to 122 For alphabets, Think of index starting wit A 0 65 B 1 65+1 C 2 65+2 D 3 65+3 ......... J 9 65+9=74 a 0 97 b 1 98=97+1 c 2 99=97+2 d 3 100 ............... j 9 97+9=106
  • 41. 41 Binary to ASCII conversion ●Starting from the right (LSB), Group every 7 bits together ●For each group of 7 bits, Determine the corresponding decimal value ●Use ASCII table to find the ASCII code for each group
  • 42. 42 Binary to ASCII conversion Example 1 q. Convert 10010110110001 to ASCII ●First, we make 7-bit groups, starting with the LSB ●1001011 0110001 ●Next, we convert each 7-bit binary to decimal number
  • 43. 43 In decimal, ●1001011 6 5 4 3 2 1 0 ●= 1x20 + 1x21 + 0x22 + 1x23 + 0x24 + 0x25 + 1x26 ●= 1 + 2 + 8 + 64 = 75 ●0110001 6 5 4 3 2 1 0 ●= 1x20 + 0x21 + 0x22 + 0x23 + 1x24 + 1x25 + 0x26 ●= 1 + 16 + 32 = 49 ●
  • 44. 44 ●Finally, we find the corresponding ASCII values 75 in ASCII = K 49 in ASCII = 1 ●So, 10010110110001 in ASCII is K1
  • 45. 45 ASCII to Binary Conversion Example 1 q. Convert Mp4 in ASCII to Binary ●First, find the corresponding decimal numbers for each ASCII character ●M p 4 77 112 52
  • 46. 46 ●Next, convert each decimal number to binary ●77 in binary: 2|77 – 1 2|38 – 0 2|19 – 1 2| 9 – 1 2| 4 – 0 2| 2 – 0 1 ●112 in binary: 2|112 – 0 2|56 – 0 2|28 – 0 2|14 – 0 2| 7 – 1 2| 3 – 1 1 ●52 in binary: 2|52 – 0 2|26 – 0 2|13 – 1 2| 6 – 0 2| 3 – 1 1
  • 47. 47 ●Next, each of the binary numbers will placed in order of their corresponding decimal numbers ●So, 77 112 52 1001101 1110000 0110100 ●Since we are converting ASCII to binary, all binary representations have to be of 7-bits ●Here, binary for 52 is of 6 bits, so we add 0 at LSB
  • 48. 48 ●So, each binary has to be converted to 7-bit form by adding 0s to the LSB as required ●Finally, the Binary form of ASCII Mp4 is = ● (1001101 1110000 0110100)2
  • 49. 49 BCD, ASCII, EBCDIC, Gray codes and their conversions
  • 50. 50 EBCDIC Code ●Extended Binary Coded Decimal Interchange Code ●8-bit representation in binary form ●Mainly used in IBM Mainframe machines ●Extension of Binary Coded Decimal form ●Makes use of fixed, 4-bit ‘Zone’ bits with 4-bit binary representation of digits etc.
  • 51. 51 EBCDIC Code equivalent for Digits 0-9 Character EBCDIC Code Zone Digit 0 1111 0000 1 1111 0001 2 1111 0010 3 1111 0011 4 1111 0100 5 1111 0101 6 1111 0110 7 1111 0111 8 1111 1000 9 1111 1001 ●4-bit Zone bits for digits is 1111 ●The 4-bit binary representation is same as BCD codes
  • 52. 52 EBCDIC Code equivalent for Alphabets Character EBCDIC Zone Digits A 1100 0001 B 1100 0010 C 1100 0011 D 1100 0100 E 1100 0101 F 1100 0110 G 1100 0111 H 1100 1000 I 1100 1001 ●The 26 alphabets are divided in 3 groups A to I (9), J to R (9), and S to Z (8) ●Each group has separate 4-bit Zone bits: A to I: 1100 ●For each group, the digit value goes from 1 to 9, and ●corresponding 4-bit binary is used
  • 53. 53 EBCDIC Code equivalent for Alphabets Character EBCDIC Zone Digit J 1101 0001 K 1101 0010 L 1101 0011 M 1101 0100 N 1101 0101 O 1101 0110 P 1101 0111 Q 1101 1000 R 1101 1001 ●For this group, the 4-bit Zone bits are J to R: 1101 ●The digit value goes from 1 to 9, and so the same corr
  • 54. 54 EBCDIC Code equivalent for Alphabets Character EBCDIC Zone Digit S 1110 0010 T 1110 0011 U 1110 0100 V 1110 0101 W 1110 0110 X 1110 0111 Y 1110 1000 Z 1110 1001 ●For this group, the 4-bit Zone bits are S to Z: 1110 ●The digit value goes from 2 to 9, and so the same ● corresponding 4-bit binary is used
  • 55. 55 Decimal Number to EBCDIC Example 1 q. Convert 425 to EBCDIC ●First, determine the zone bits – here it is 1111 (for digits) ●Next, find the BCD of each decimal digit: ●4 5 2 0100 0010 0101
  • 56. 56 ●To the BCDs, append the Zone bits at LSB 4 2 5 11110100 11110010 11110101 ●Bring the 8-bit codes together in order to get the final EBCDIC representation: ●11110100 11110010 11110101
  • 57. 57 EBCDIC to Character Example 1 q. Convert the following EBCDIC to Decimal: 1111100111111000 ●First, make groups of 8-bits each starting from the right 11111001 11111000
  • 58. 58 ●The first 4-bits of each group represents Zone bits,use it to identify the type of data ●Here Zone bits = 1111, so we have digits ●For each group, starting with the right, extract the 4 digit bits and find their corresponding decimal value ●11111001 11111000 1001 1000
  • 59. 59 In decimal, 1001 3 2 1 0 = 1x20 +1x23 = 9 1000 3 2 1 0 = 1x23 = 8 So, placing the decimal digits in order, the converted value of given EBCDIC code = 98
  • 60. 60 BCD, ASCII, EBCDIC, Gray codes and their conversions
  • 61. 61 Gray Code ●Named after scientist Frank Gray ●Called ‘Reflected Binary code’ ●Expressions for sequential numbers differ only by 1 bit ●So, binary expressions are converted to Gray Code to minimize switching operations ●Also called ‘Unit Distance Code’, ‘Cyclic Code’
  • 62. 62 Binary to Gray Code conversion ●Take the MSB – this is the MSB for Gray Code ●Add MSB to next bit of Binary, keep the sum and ignore carry (XOR) – the sum is the 2nd bit after MSB in Gray Code ●Keep shifting bit by bit towards right, and repeat the above two steps to obtain the complete Gray Code
  • 63. 63 Generalized Rule ●If a binary number b3b2b1b0 is to be converted to Gray Code g3g2g1g0, ●g3 = b3, ●g2=b3⊕b2 ●g1=b2⊕b1 ●g0=b1⊕b0
  • 64. 64 Example of Binary to Gray Code convertion q. Convert 1101 to Gray Code Step 1: ●MSB of 1101 is 1 ●So, MSB of Gray Code is set as 1 Binary: 1 1 0 1 Gray Code:1
  • 65. 65 Example of Binary to Gray Code convertion Step 2: ●Add MSB (1) to ne ●Set the sum (0) a ●Ignore the carry Binary: 1 1 0 1 + Gray Code: 1 0
  • 66. 66 Example of Binary to Gray Code convertion Step 3: ●Add succeeding bi ●Set the sum (1) a ●Ignore the carry Binary: 1 1 0 1 + Gray Code: 1 0 1
  • 67. 67 Example of Binary to Gray Code conversion Step 4: ●Add succeeding bi ●Set the sum (1) a ●Ignore the carry Binary: 1 1 0 1 + Gray Code: 1 0 1 1
  • 68. 68 Gray Code to Binary conversion ●Take the MSB – this is the MSB for Gray Code ●Add MSB to next bit of Gray Code, keep the sum and ignore carry (XOR) – the sum is the 2nd bit after MSB ●Keep shifting bit by bit towards right, and repeat the above two steps to obtain the complete Gray Code
  • 69. 69 Generalized Rule ●If a Gray Code g3g2g1g0 is to be converted to binary number b3b2b1b0, ●b3 = g3, ●b2=b3⊕g2 ●b1=b2⊕g1 ●b0=b1⊕g0
  • 70. 70 Example of Gray Code to Binary conversion q. Convert 1011 to Binary Step 1: ●MSB of 1011 is 1 ●So, MSB of Binary Gray Code: 1 0 1 1 Binary: 1
  • 71. 71 Example of Gray Code to Binary conversion Step 2: ●XOR the MSB (1) t ●Set the result (1 Gray Code: 1 0 1 1 ⊕ Binary: 1 1
  • 72. 72 Example of Binary to Gray Code convertion Step 3: ●XOR the succeesin ●Set the result (0 Gray Code: 1 0 1 1 ⊕ Binary: 1 1 0
  • 73. 73 Example of Binary to Gray Code conversion Step 4: ●XOR the succeesin ●Set the result (1 Gray Code: 1 0 1 1 ⊕ Binary: 1 1 0 1