Lecture 2 (1)
Lecture 2 (1)
10110.11 = (22.75)10
6.25)10
BINARY CODE
• The digital data is represented, stored and transmitted as a group of binary bits. This
group is also called binary code.
• Weighted:
• Non-weighted
BINARY CODE
• Weighted Binary Codes:
• In w eighted code, each digit position has a weight or value.
• The sum of all digits multiplied by a weight gives a total amount being
represented.
• BCD or 8421 is a type of weighted code where each digit position is assigned a
specific weight.
• If x1, x2, x3, x4 are the binary digits, with weights w1 , w2 , w3 , w4 , then
the decimal digit is: N=w 4 x 4 +w 3 x 3 +w 2 x 2 +w 1 x 1
• We say, the sequence (x1, x2, x3, x4) denotes the code word for N.
WEIGHTED BINARY CODE
Self-complementing code:
Code word of 9’s complement of N obtained by interchanging 1’s and 0’s in the code word of N
NON WEIGHTED BINARY CODE
• In non-weighted code there is no positional weight i.e., Each position within the
binary number is not assigned a prefix value.
• Gray code
• Excess-3 code.
BCD TO EXCESS 3 CODE
• Excess-3 codes are unweighted and can be obtained by adding 3 to each decimal
digit then it can be represented by using 4-bit binary number for each digit.
• To find the decimal equivalent of the given binary number. Add 0011 to each four-
bit group in binary coded decimal number (BCD) to get desired excess-3
equivalent.
• The variables B0, B1, B2, and B3 represent the bits of the binary numbers.
• The variable 'B 0 ' represents the LSB, and the variable 'B 3 ' represents the MSB.
• The variables E0, E1, E2, and E3 represent the bits of the Excess-3 code.
• The variable 'E 0 ' represents the LSB, and the variable 'E 3 ' represents the MSB.
BCD TO EXCESS 3 CODE
• The truth table for BCD to Excess-3 code converter can be determined as shown in the
table below.
• For impossible four-bit Excess-3 code, we use the output as Don’t care conditions. The
'don't care conditions' is defined by the variable 'X'.
BCD Number Excess-3 Code Number
Decimal B3 B2 B1 B0 E3 E2 E1 E0
0 0 0 0 0 0 0 1 1
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
BCD TO GRAY CODE CONVERSION
The Gray code is non-weighted code, as the position of bit does not contain any weight.
The Gray code is a reflective digital code which has the special property that any two subsequent
numbers codes differ by only one bit.
G 3 = Β3 G 2 = Β 3⊕ Β 2 G 1 = Β 2⊕ Β 1 G 0 = Β 1⊕ Β 0
The most significant bit (MSB) of the Gray code is always equal to the MSB of the given
binary code.
Other bits of the output Gray code can be obtained by XORing binary code bit at that
index and the previous index.
BCD TO GRAY CODE CONVERSION
Four Bit Binary
Four Bit Gray Code
Number
Decimal B3 B2 B1 B0 G3 G2 G1 G0
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 1
3 0 0 1 1 0 0 1 0
4 0 1 0 0 0 1 1 0
5 0 1 0 1 0 1 1 1
6 0 1 1 0 0 1 0 1
7 0 1 1 1 0 1 0 0
8 1 0 0 0 1 1 0 0
9 1 0 0 1 1 1 0 1
GRAY TO BCD CONVERSION
In Gray to binary conversion, the input is Gray code and output is its
equivalent binary code.
Β3 = G3 Β2 = G2 ⊕ Β3 Β1 = G1 ⊕ Β2 Β0 = G0 ⊕
Β1
SIGNED AND UNSIGNED BINARY
SIGNED AND UNSIGNED
• Unsigned binary: BINARY
• N bit binary number represents its magnitude only.
• Range 0 to (2n-1)
• If this bit is set to 1, the number will be negative else the number will be
positive if it is set to 0.
• Apart from this sign-bit, the n-1 bits represent the magnitude of the number.
• Two representation of the number zero (0), positive (+0) and negative (-0).
• Zero (0) can have two representations, that’s why 1’s complement form is also
ambiguous form.
• Range of 6 bit 1’s complement form binary number is from -(25-1) to (25-1) which is
equal from minimum value -31 (i.e., 1 00000) to maximum value +31 (i.e., 0 11111).
• Zero (0) has two representation, -0 (i.e., 1 11111) and +0 (i.e., 0 00000).
SIGNED AND UNSIGNED BINARY
• 2’s complement form:
• 2’s complement of a number is obtained by inverting each bit of a given number plus
1 to least significant bit (LSB).
• So, we represent positive numbers in binary form and negative numbers in 2’s
complement form.
• If the value of the most significant bit (MSB) is 1, then take 2’s complement, else not.
• Zero (0) has only one (unique) representation which is always positive.
• Range of 6 bit 2’s complement form binary number is from -(25) to (25-1) which is
equal from minimum value -32 (i.e., 1 00000) to maximum value +31 (i.e., 0 11111).
SIGNED AND UNSIGNED
BINARY
• Represent +6 and -6