0% found this document useful (0 votes)
9 views18 pages

DLD3

Uploaded by

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

DLD3

Uploaded by

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

Chapter 4

Digital Binary Codes


In this chapter:

we will introduce four different codes where 4 bits are used to represent a single
decimal digits and/or characters.
Binary Coded Decimal (BCD)
The binary system is the natural one for computers but people are accustomed to decimal
system.
For this to be resolved we need to convert all decimals to binary then do all the arithmetic
operations then return them to decimal. It will be easier to represent directly decimals in binary
bits so we can do arithmetic operations directly.
A set of 4 elements can be coded with 2 bits. The combinations
of n-bit code are from 0 to 2n-1. Decimal BCD
A set of 10 elements can be coded with 4 bits. The combinations Equivalent Digit
of 4-bit code are from 0 to 15. 6 out of the 16 combinations 0 0000
are unassigned.
1 0001
A number of n decimal digits will require 4n bits in BCD.
2 0010
3 0011
(396)10=(??????????????)BCD
4 0100
(396)10=(0011 1001 0110)BCD
5 0101
6 0110
(185)10= (??????????????)BCD
7 0111
(185)10= (??????????????)2
8 1000
(185)10= (0001 1000 0101)BCD= (10111001)2
9 1001
Addition in BCD
How can we add two BCD numbers??
Since each decimal digit can’t hold more than 9 then the maximum sum of 2 digits is 9+9+1
where 1 is for carry from lower significant digit. Then the result is between 0 and 19.
In binary this is between 0000 to 10011 but in BCD it should be 0000 to 1 1001.

If sum <= 1001, sum is correct.


Decimal BCD
If sum > 1001, sum is incorrect. We need to add 6 or 0110 to Equivalent Digit
get the correct sum. 0 0000
1 0001
Example: 2 0010
(9)10+(5)10=(14)10 3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
Lets do it practically:

(448)10+(489)10=(????)10 (448)10+(489)10=(937)10

Column # 5 4 3 2 1 Column # 5 4 3 2 1
Carries 0 0 0 1 Carries 0 0 0
1st number 0 1 0 0 1st number 1 0 0 0
2nd number + 1 0 0 0 2nd number + 1 0 0 1
1 1 0 1 1 0 0 0 1
0 1 1 0 0 1 1 0
Sum 1 0 0 1 1 Sum 1 0 1 1 1

Column # 5 4 3 2 1
Carries 0 0 0 1
1st number 0 1 0 0
2nd number + 0 1 0 0
Sum 1 0 0 1
Excess-3 Code
The excess 3 code for a decimal digit is the binary combination of the decimal digit plus 3. The
code has desirable properties when implementing decimal subtraction.

For Addition: If sum has Decimal BCD Excess-3


produced a carry we have to add Digit
0011 with them and subtract
0011 from the sum which has 0 0 0 0 0 0 0 1 1
not produced a carry. 1 0 0 0 1 0 1 0 0
2 0 0 1 0 0 1 0 1
3 0 0 1 1 0 1 1 0
4 0 1 0 0 0 1 1 1
5 0 1 0 1 1 0 0 0
6 0 1 1 0 1 0 0 1
7 0 1 1 1 1 0 1 0
8 1 0 0 0 1 0 1 1
9 1 0 0 1 1 1 0 0
Lets do it practically:
(0110 1000 1001)E3+(1000 1010 1100)E3=(????)E3

Column # 5 4 3 2 1 Column # 5 4 3 2 1
Carries 0 0 0 1 Carries 0 0 0
1st number 1 0 0 0 1st number 1 0 0 1
2nd number + 1 0 1 0 2nd number + 1 1 0 0
1 0 0 1 1 1 0 1 0 1
+ 0 0 1 1 + 0 0 1 1
Sum 1 0 1 1 0 Sum 1 1 0 0 0
Column # 5 4 3 2 1
Carries 0 0 0 1
1st number 0 1 1 0
(356)10+(579)10=(935)10
2nd number + 1 0 0 0
1 1 1 1
- 0 0 1 1
Sum 1 1 0 0
Excess-3 Code

For Subtraction: If subtraction Decimal BCD Excess-3


need a borrow then we have to Digit
subtract 0011 and if subtraction
don’t need a borrow then we 0 0 0 0 0 0 0 1 1
need to add 0011. 1 0 0 0 1 0 1 0 0
2 0 0 1 0 0 1 0 1
3 0 0 1 1 0 1 1 0
4 0 1 0 0 0 1 1 1
5 0 1 0 1 1 0 0 0
6 0 1 1 0 1 0 0 1
7 0 1 1 1 1 0 1 0
8 1 0 0 0 1 0 1 1
9 1 0 0 1 1 1 0 0
Lets do it practically:
(1001 1000 1100)E3 -(0110 1010 1001)E3=(????)E3

Column # 5 4 3 2 1 Column # 5 4 3 2 1
Borrow 1 1 0 Borrow 0 1 1
1st number 1 0 0 0 1st number 1 1 0 0
2nd number - 1 0 1 0 2nd number - 1 0 0 1
1 1 1 0 0 0 1 1
- 0 0 1 1 + 0 0 1 1
Sum 1 0 1 1 Sum 0 1 1 0
Column # 5 4 3 2 1
Borrow 1 1 0 1
1st number 1 0 0 1
(659)10-(376)10=(283)10
2nd number - 0 1 1 0
0 0 1 0
+ 0 0 1 1
Sum 0 1 0 1
2*421 Code
The decimal digits are divided into two groups . The first five digits with 0 bit on the msb and
the second five with 1 bit on the msb.

Express (448)10 in the 2421 code? Decimal 2*421


Digit
Express (489)10 in the 2421 code? 0 0 0 0 0
1 0 0 0 1
How the 2421 code is a complementing one? 2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 1 0 1 1
6 1 1 0 0
7 1 1 0 1
8 1 1 1 0
9 1 1 1 1
Gray Codes
As we count up from 000 to 111 and back to 000, the number of bits Binary Bit
that change ranges from 1 to 3. Code Changes
There are applications in which
111 000 000
a change of more than one bit
.when counting up or down can B0 001 1
cause serious problems. 010 2
110 B1 001
B2 011 1
Problem: Shaft is positioned at
the boundary between 011 and 100 3
100. 101 1
Light is partially blocked so 101 010
110 2
unclear situation happens. We
can have 000, 001, 010, 011, 111 1
100, 101, 110 and 111. 100 011 000 3
Either 011 and 100 will be true
Optical Shaft Angle Encoder Total 14
but other six values are wrong.
Problem: Shaft is positioned at Clear areas for binary 1 and dark areas for
the boundary between 010 and binary 0. An illumination source is placed
011. on one side and sensors are placed on the
We can have 010 or 011. Both other side one/bit.
are true.
We need to change the order of the encoding so that only one bit
value changes as we count up or down.
A specific gray code for the octal Gray Bit
digits called the Binary Code Changes
Reflected Gray Code is shown. 000 000
100
001 1
011 1
101 001
010 1
110 1
G2
G1 111 1
G0
111 011 101 1
100 1
110 010 000 1
Optical Shaft Angle Encoder Total 8
using Gray Code concept
With continuous counting, there are 14 bit changes for binary counting
for every 8 bit changes for Gray Code counting. Power consumed for
Gray Code counting is 57% of that consumed at the binary counting.
Parity Bit
To detect errors, an additional parity bit is added to numbers to define their parity.
A parity bit is an extra bit included to make the total number of ones in the binary code either
even or odd parity.
We add an extra bit in the most significant bit to make the number of ones even for even parity
or odd for odd parity.

With Even Parity With Odd Parity


7 6 5 4 3 2 1 8 7 6 5 4 3 2 1 8 7 6 5 4 3 2 1
1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1
1 0 1 0 1 0 0 1 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0

Even parity is more commonly used than odd parity.


The American Standard Code for
Information Interchange (ASCII) Code
ETX: End of Text.
EOT: End of
Transmission.
ENQ: Enquiry.
ACK: Acknowledgement
BS: Back space.
TAB: Horizontal Tab.
LF: Line Feed/ with no
return.
VT: Vertical Tab.
FF: Form Feed.
CR: Carriage Return.
DC1: Device Control.
NAK: Negative
Acknowledgement
SYN: Synchronous.
ETB: End of
Transmission.
CAN: Cancel.
Example1:
Express the sentence:

SO LONG.

in ASCII code without


parity?
Example2:
Express the sentence:

Print

in ASCII code with even


parity bit and place it in
msb possible?
Cyclic Codes/
Error Detecting Codes
A class of cyclic codes is very effective in detecting and correcting randomly occurring multiple
errors.
Lets see how??
Using polynomials we can write:
Example3:

Find T(x) if M(x)=101101 and G(x)=11001.

Solution:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy