W2L2_Binary_Codes
W2L2_Binary_Codes
4/9/2020
Weighted Codes
• Need to represent the 10 decimal numbers (0, 1,, 2, …, 9).
• 4 binary bits are needed for this (16 possible representations)
• There are many codes possible.
• Each binary digit is assigned a decimal “weight”.
• If w1, w2, w3, and w4 are the given weights of the binary digits and x1, x2, x3,
x4 the corresponding digit values then the decimal digit
• N = w4 x4 + w3 x3 + w2 x2 + w1 x1 can be represented by the binary sequence
x4x3x2x1.
• The sequence of binary digits that represents a decimal digit is called a code
word.
Weighted Codes
• The sequence x4x3x2x1 is the code word for N.
• The code word 8, 4, 2, 1 is known as Binary Coded Decimal (BCD).
Self-complementing codes
• It is apparent that the representations of some decimal numbers in
the (2, 4, 2, 1) and (6, 4, 2,−3) codes are not unique.
• For example, in the (2, 4, 2, 1) code, decimal 7 may be represented by 1101 as
well as 0111.
• Adopting the representations shown in Table causes the codes to
become self-complementing.
• A code is said to be self-complementing if the code word of the “9’s
complement of N”, i.e., 9 − N, can be obtained from the code word of
N by interchanging all the 1’s and 0’s.
• For example, in the (6, 4, 2,−3) code, decimal 3 is represented by 1001 while
decimal 6 is represented by 0110.
Self-complementing codes
• BCD code (8, 4, 2, 1) is not self-complementing.
• A necessary condition for a weighted code to be self-complementing is that the
sum of the weights must equal 9.
• There exist only four positively weighted self-complementing codes, namely,
(2, 4, 2, 1), (3, 3, 2, 1), (4, 3, 1, 1), and (5, 2, 1, 1).
• There exist 13 self-complementing codes with positive and negative weights.
• (6 4 2 -3)
Nonweighted codes
• There are many nonweighted binary codes, such as Excess-3 Code,
Cyclic Code, Gray Code etc..
• The Excess-3 code is formed by adding 0011 to each BCD code word.
4/9/2020
Cyclic Code Property
• Linearity property: The sum of any two code words in the code is also
a code word
• Cyclic property: Any cyclic shift of a code word in the code is also a
code word.
Cyclic codes
• Code word having property of successive decimal integers differ in
only one digit are referred to as cyclic codes.
• Gray code also have property of successive decimal integers differ
by 1 bit, so it is also a cyclic code.
• Code useful is the simplicity of the procedure for converting from the
binary number system into the Gray code
4/9/2020
Gray Code
• Gray code is cyclic
• It is easy to convert Binary number to Gray code
Binary code to gray code conversion
• Let gn · · · g2 g1 g0 denote a code word in the (n + 1)th-bit Gray code,
and let bn · · · b2b1 b0 designate the corresponding binary number.
4/9/2020
Gray Code to Binary
• Start with the leftmost digit and proceed to the least significant digit
• Set bi = gi if the number of 1’s preceding gi is even
• Set bi = gi’ if the number of 1’s preceding gi is odd
• Gray code word 1001011 represents the binary number 1110010
Reflected Code
• The term “reflected” is used to
designate codes which have the
property that the n-bit code can be
generated by reflecting the (n − 1)th-bit
code.
• Three-bit Gray code can be obtained by
reflecting the two-bit code about an axis
at the end of the code and assigning a
most significant bit of 0 above the axis
and 1 below the axis.
Thank You