0% found this document useful (0 votes)
4 views

Lec 4 Binary Codes

Uploaded by

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

Lec 4 Binary Codes

Uploaded by

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

DIGITAL LOGIC DESIGN

LEC 4: BINARY CODES

LECTURER MEHREEN JAVAID


Signed Binary Numbers
• To represent negative integers, we need a notation for
negative values.
• It is customary to represent the sign with a bit placed in
the leftmost position of the number since binary digits.
• The convention is to make the sign bit 0 for positive and
1 for negative.
Signed Binary Numbers
• Signed-Magnitude Representation: Negates a number
by changing its sign.
• Complement Number Systems: negates a number by
taking its complement.
• One’s-Complement
• Two’s-Complement
Signed Binary Numbers
•Example: Representation of -9
Signed Binary Numbers
Signed Binary Numbers
Signed Binary Numbers
• Arithmetic addition
• The addition of two numbers in the signed-magnitude system
follows the rules of ordinary arithmetic. If the signs are the
same, we add the two magnitudes and give the sum the
common sign. If the signs are different, we subtract the smaller
magnitude from the larger and give the difference the sign if the
larger magnitude.
• The addition of two signed binary numbers with negative
numbers represented in signed-2's-complement form is obtained
from the addition of the two numbers, including their sign bits.
• A carry out of the sign-bit position is discarded.
Signed Binary Numbers
Example:
Signed Binary Numbers
Signed Binary Numbers
• Arithmetic Subtraction
• In 2’s-complement form:

1. Take the 2’s complement of the subtrahend (including the sign


bit) and add it to the minuend (including sign bit).
2. A carry out of sign-bit position is discarded.

( A)  (  B ) ( A)  (  B )
( A)  (  B ) ( A)  (  B )
( 6)  ( 13)
• Example: (11111010  11110011)
(11111010 + 00001101)
00000111 (+ 7)
Signed Binary Numbers
Binary Codes
• BCD Code
• A number with k decimal digits will require 4k bits in BCD.
• Decimal 396 is represented in BCD with 12bits as 0011 1001
0110, with each group of 4 bits representing one decimal digit.
• A decimal number in BCD is the same as its equivalent binary
number only when the number is between 0 and 9.
• The binary combinations 1010 through 1111 are not used and
have no meaning in BCD.
• Examples are digital wrist watches, calculators, voltmeter etc.
Binary Codes
Binary Codes
•BCD addition
• Step 1: Add the two BCD numbers, using the rules
for binary addition
• Step 2: If a 4-bit sum is equal to or less than 9, it is a
valid BCD number.
• Step 3: 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 six invalid states and return the code to
8421.
• If a carry results when 6 is added, simply add the carry to
the next 4-bit group.
Binary Codes
• Example:
• Consider decimal 185 and its corresponding value in BCD and
binary:

• BCD addition
Binary Codes
• Example:
• Consider the addition of 184 + 576 = 760 in BCD:
Binary Codes
Add the following numbers in BCD:
• 12+29
• 18+54
• 86+13
• 901+337
Binary Codes
• Other Decimal Codes
Binary Codes
Gray Code
The advantage is that only one bit in the code group
changes in going from one number to the next.
Gray Code

•Binary Code more than 1 bit change


•Electromechanical applications of digital systems
restrict bit change to 1
• Shaft encoders
• Braking Systems

•Un-Weighted Code
Binary Codes
Binary-to-Gray Code Conversion:
1. The most significant bit (left-most) in the Gray code is the
same as the corresponding MSB in the binary number.
2. Going from left to right, add each adjacent pair of binary
code bits to get the next Gray code bit. Discard carries.

The Gray code is 11101.


Binary Codes
Gray-to-Binary Code Conversion:
1. The most significant bit (left-most) in the binary code is the
same as the corresponding bit in the Gray code.
2. Add each binary code bit generated to the Gray code bit in
the next adjacent position. Discard carries.

The binary number is 10010.


Binary Codes
ASCII Character Codes
• American Standard Code for Information Interchange (Refer
to Table 1.7)
• A popular code used to represent information sent as
character-based data.
• It uses 7-bits to represent:
• 94 Graphic printing characters.
• 34 Non-printing characters.
• Some non-printing characters are used for text format (e.g.
BS = Backspace, CR = carriage return).
• Other non-printing characters are used for record marking
and flow control (e.g. STX and ETX start and end text areas).
Codes and Characters
• Each character is coded as a byte
• Most common coding system is ASCII
• ASCII = American National Standard Code for
Information Interchange
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
000 001 010 011 100 101 110 111
0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # significant
Most 3 C S c s
0100 EDT DC4 $ bit 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 LeastVT
significantESC + ; K [ k {
1100 FFbit FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
e.g., ‘a’ =
1100001

000 001 010 011 100 101 110 111


0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
95 Graphic
codes

000 001 010 011 100 101 110 111


0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
33 Control
codes

000 001 010 011 100 101 110 111


0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
Alphabetic
codes

000 001 010 011 100 101 110 111


0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
Numeric
codes

000 001 010 011 100 101 110 111


0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
Punctuation,
etc.

000 001 010 011 100 101 110 111


0000 NULL DLE 0 @ P ` p
0001 SOH DC1 ! 1 A Q a q
0010 STX DC2 " 2 B R b r
0011 ETX DC3 # 3 C S c s
0100 EDT DC4 $ 4 D T d t
0101 ENQ NAK % 5 E U e u
0110 ACK SYN & 6 F V f v
0111 BEL ETB ' 7 G W g w
1000 BS CAN ( 8 H X h x
1001 HT EM ) 9 I Y i y
1010 LF SUB * : J Z j z
1011 VT ESC + ; K [ k {
1100 FF FS , < L \ l |
1101 CR GS - = M ] m }
1110 SO RS . > N ^ n ~
1111 SI US / ? O _ o DEL
Error Detection

•Digital Systems are very Reliable


•Errors during storage or transmission
•Parity Bit
• Even Parity
• Odd Parity
Odd Parity Error Detection

•Original data 10011010


•With Odd Parity 110011010
•1-bit error 110111010
•Number of 1s even indicates 1-bit error
•2-bit error 110110010
•Number of 1s odd no error indicated
•3-bit error 100110010
•Number of 1s even indicates error

You might also like