Binary Codes & By Ratnesh sir Introduction

The first successful system of electrical communication was the telegraph, which was invented by Samuel F.B. Morse in the year 1832. The telegraph operators used a code of clicks to send the messages. If the key pressed for a short time it is the Morse code called ‘dot’ and if the key pressed for a long- time it is ‘Dash’. A sample Morse code is shown below:

Weighted codes

In weighted codes, each digit is assigned a specific weight according to its position. For example, in 8421BCD code, 1001 the weights of 1, 0, 0, 1 (from left to right) are 8, 4, 2 and 1 respectively.

Suppose W1' W2' W3 and W4 are the weights of binary digits and Xl' X2,

X3 and X4 are the corresponding digit values then decimal digit. N =

W1 Xl + W2 X2 + W3 X3 + W4 X4 is represented by binary sequence

X4 X3 X2 X4.

The codes 8421BCD, 2421BCD, 5211BCD are all weighted codes Non-weighted codes:

The non-weighted codes are not positionally weighted. In other words, each digit position within the number is not assigned a fixed value ( or weight ).

Excess-3 and gray code are non-weighted codes. Reflective codes:

A code is reflective when the code is self complementing. In other words, when the code for 9 is the complement the code for 0, 8 for 1, 7 for 2, 6 for 3 and 5 for 4.

2421BCD, 5421BCD and Excess-3 code are reflective codes. Sequential codes:

In sequential codes, each succeeding 'code is one greater than its preceding code. This property helps in manipulation of .

8421 BCD and Excess-3 are sequential codes Alphanumeric codes:

Codes used to represent numbers, alphabetic characters, symbols and various instructions necessary for conveying intelligible information.

ASCII, EBCDIC, UNICODE are the most-commonly used alphanumeric codes.

ASCII------American Standard Code for Information Interchange

EBCDIC ------Extended Binary Coded Decimal Interchange Code Error defecting and correcting codes:

Codes which allow error defection and correction are called error detecting and' correcting codes.

Hamming code is the mostly commonly used error detecting and correcting code Binary Weights

Whenever any binary number appears, its decimal equivalent can be found easily as follows. When there is 1 in a digit position, weight of that position should be added. When there is 0 in a digit position, weight of that position should be disregarded.

For example binary number 1101 has a decimal equivalent of 8 + 4 + 0 + 1 = 13. 8421 Code or BCD Code

The decimal numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 can be expressed in Binary numbers as shown below. All these binary numbers again expressed in the last column by expanding into 4 . As per the weighted binary digits, the 4 binary numbers can be expressed according to their place value from left to right as 8421 (2³ 2² 2¹ 2⁰ = 8421). 4 BIT DECIMAL NUMBER BINARY NUMBER EXPRESSION(8421) 0 0 0000 1 1 0001 2 10 0010 3 11 0011 4 100 0100 5 101 0101 6 110 0110 7 111 0111 8 1000 1000 9 1001 1001 2421 Code This code also a 4 bit application code where the binary weights carry 2, 4, 2, 1 from left to right.

DECIMAL NUMBER BINARY NUMBER 2421 CODE 0 0 0000 1 1 0001 2 10 0010 3 11 0011 4 100 0100 5 101 1011 6 110 1100 7 111 1101 8 1000 1110 9 1001 1111 This code is also a 4 bit application code where the binary weights carry 5, 4, 2, 1 from left to right.

DECIMAL NUMBER BINARY NUMBER 5211 CODE 0 0 0000 1 1 0001 2 10 0011 3 11 0101 4 100 0111 5 101 1000 6 110 1010 7 111 1100 8 1000 1110 9 1001 1111 Reflective Code

It can be observed that in the 2421 and 5211 codes, the code for decimal 9 is the complement of the code for decimal 0, the code for decimal 8 is the complement of the code for decimal 1, the code for decimal 7 is the complement of the code for decimal 2, the code for decimal 6 is the complement of the code for decimal 3, the code for decimal 5 is the complement of the code for decimal 4, these codes are called as reflexive codes. DECIMAL DECIMAL 2421 CODE 5211 CODE NUMBER NUMBER 0 0 0000 0000 1 1 0001 0001 2 10 0010 0011 3 11 0011 0101 4 100 0100 0111 5 101 1011 1000 6 110 1100 1010 7 111 1101 1100 8 1000 1110 1110 9 1001 1111 1111 Sequential codes:

In sequential codes, each succeeding 'code is one binary number greater than its preceding code. This property helps in manipulation of data DECIMAL BINARY NUMBER 8421 CODE EXCESS-3 NUMBER 0 0 0000 0011 1 1 0001 0100 2 10 0010 0101 3 11 0011 0110 4 100 100 0111 5 101 0101 1000 6 110 0110 1001 7 111 0111 1010 8 1000 1000 1011 9 1001 1001 1100 Non-Weighted Codes

Some of the codes will not follow the weights of the sequence binary numbers these are called as non-weighted codes. ASCII code ,Grey code and XS-3 are some of the examples where they are coded for some special purpose applications and they do not follow the weighted binary number calculations. Excess-3 Code

Some of the codes will not follow the binary weights, Excee-3 code is an example of it and it is an important 4 bit code. The excess – 3 code of a decimal number is achieved by adding the number 3 to the 8421 code. Non-Weighted Codes

Some of the codes will not follow the weights of the sequence binary numbers these are called as non-weighted codes. ASCII code ,Grey code and XS-3 are some of the examples where they are coded for some special purpose applications and they do not follow the weighted binary number calculations. Excess-3 Code

Some of the codes will not follow the binary weights, Excee-3 code is an example of it and it is an important 4 bit code. The excess – 3 code of a decimal number is achieved by adding the number 3 to the 8421 code.

Decimal BCD + 0011 Excee-3 Decimal Digit BCD Code Excess-3 Code

0 0000 0011

1 0001 0100

2 0010 0101

3 0011 0110

4 0100 0111

5 0101 1000

6 0110 1001

7 0111 1010

8 1000 1011

9 1001 1100 Advantages of Excess-3 Codes:

These are following advantages of Excess-3 codes, These are unweighted binary decimal codes. These are self-complementary codes. The codes 0000 and 1111 are not used for any digit which is an advantage for memory organization as these codes can cause fault in transmission line. It has no limitation, and it considerably simplifies arithmetic operations. It is particularly significant for arithmetic operations as it overcomes shortcoming encountered while using 8421 BCD code to add two decimal digits whose sum exceeds 9. Gray Code

The gray code is the code where one bit will be differed to the preceding number. Gray code is not weighted that means it does not depends on positional value of digit. This cyclic variable code that means every transition from one value to the next value involves only one bit change. Conversion of Binary to Gray Code:

The hamming distance of two neighbours Gray codes is always 1 and also first Gray code and last Gray code also has Hamming distance is always 1, so it is also called Cyclic codes.

Gray codes are used in rotary and optical encoders, Karnaugh maps, and error detection.. Using Karnaugh (K) - map:

Decimal Binary Gray Code

0 000 000

1 001 001

2 010 011

3 011 010

4 100 110

5 101 111

6 110 101

7 111 100 Using Exclusive-Or (⊕) operation:

These are following steps for n-bit binary numbers:

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 the index and previous index. Binary Gray Code b2 b1 b0 g2 g1 g0

000 000

001 001

010 011

011 010

100 110

101 111

110 101

111 100

Error Detection & Correction Codes- Hamming Code

We know that the bits 0 and 1 corresponding to two different range of analog voltages. So, during transmission of binary data from one system to the other, the noise may also be added. Due to this, there may be errors in the received data at other system i.e. a bit 0 may change to 1 or a bit 1 may change to 0 We can get back the original data first by detecting whether any error(s) present and then correcting those errors. For this purpose, we can use the following codes. Error detection codes Error correction codes

Error detection codes

This method are used to detect the error(s) present in the received data (bit stream). These codes contain some bit(s), which are included (appended) to the original bit stream.

Example − Parity code, Hamming code. Error correction codes −

This method are used to correct the error(s) present in the received data (bit stream) so that, we will get the original data.

Example − Hamming code

Parity Code

It is easy to include (append) one parity bit either to the left of MSB or to the right of LSB of original bit stream. There are two types of parity codes, namely even parity code and odd parity code based on the type of parity being chosen. Even Parity Code

The value of even parity bit should be zero, if even number of ones present in the binary code. Otherwise, it should be one. So that, even number of ones present in even parity code. Even parity code contains the data bits and even parity bit. Binary Code Even Parity bit Even Parity Code 000 0 0000 001 1 0011 010 1 0101 011 0 0110 100 1 1001 101 0 1010 110 0 1100 111 1 1111 Odd Parity Code

The value of odd parity bit should be zero, if odd number of ones present in the binary code. Otherwise, it should be one. So that, odd number of ones present in odd parity code. Odd parity code contains the data bits and odd parity bit. Binary Code Odd Parity bit Odd Parity Code 000 1 0001 001 0 0010 010 0 0100 011 1 0111 100 0 1000 101 1 1011 110 1 1101 111 0 1110 Hamming Code

Hamming code is useful for both detection and correction of error present in the received data. This code uses multiple parity bits and we have to place these parity bits in the positions of powers of 2. The minimum value of 'k' for which the following relation is correct (valid) is nothing but the required number of parity bits. 2k ≥ n+k+1

Where, ‘n’ is the number of bits in the binary code (information) ‘k’ is the number of parity bits

Laws of Boolean Algebra

Idempotent Law

A * A = A A + A = A

Associative Law

(A * B) * C = A * (B * C) (A + B) + C = A + (B + C)

Commutative Law

A * B = B * A A + B = B + A Distributive Law

A * (B + C) = A * B + A * C A + (B * C) = (A + B) * (A + C)

Identity Law

A * 0 = 0 A * 1 = A A + 1 = 1 A + 0 = A

Complement Law

A * ~A = 0 A + ~A = 1

Involution Law

~(~A) = A Absorption

A + (A * B) = A A * (A + B) = A In boolean algebra, the OR operation is performed by which properties? a) Associative properties b) Commutative properties c) Distributive properties d) All of the Mentioned The expression for Absorption law is given by ______a) A + AB = A b) A + AB = B c) AB + AA’ = A d) A + B = B + A According to boolean law: A + 1 = ? a) 1 b) A c) 0 d) A’ The involution of A is equal to ______a) A b) A’ c) 1 d) 0 A(A + B) = ? a) AB b) 1 c) (1 + AB) d) A DeMorgan’s theorem states that ______a) (AB)’ = A’ + B’ b) (A + B)’ = A’ * B c) A’ + B’ = A’B’ d) (AB)’ = A’ + B (A + B)(A’ * B’) = ? a) 1 b) 0 c) AB d) AB’ Complement of the expression A’B + CD’ is ______a) (A’ + B)(C’ + D) b) (A + B’)(C’ + D) c) (A’ + B)(C’ + D) d) (A + B’)(C + D’) The A + BC is a reduced form of ______a) AB + BC b) (A + B)(A + C) c) A’B + AB’C d) (A + C)B The idempotence law of Boolean algebra says that a) x + y = 1 b) x + x = x c) x + xy = x d) x(x+y) = x The expression Y=AB+BC+AC shows the ______operation. a) EX-OR b) SOP c) POS d) NOR The expression Y=(A+B)(B+C)(C+A) shows the ______operation. a) AND b) POS c) SOP d) NAND The NOR gate output will be high if the two inputs are ______a) 00 b) 01 c) 10 d) 11 A universal logic gate is one which can be used to generate any logic function. Which of the following is a universal logic gate? a) OR b) AND c) XOR d) NAND Which of following are known as universal gates? a) NAND & NOR b) AND & OR c) XOR & OR d) EX-NOR & XOR A single transistor can be used to build which of the following digital logic gates? a) AND gates b) OR gates c) NOT gates d) NAND gates How many entries are necessary for a four-input circuit? a) 4 b) 8 c) 12 d) 16 Which input values will cause an AND logic gate to produce a HIGH output? a) At least one input is HIGH b) At least one input is LOW c) All inputs are HIGH d) All inputs are LOW Exclusive-OR (XOR) logic gates can be constructed from what other logic gates? a) OR gates only b) AND gates and NOT gates c) AND gates, OR gates, and NOT gates d) OR gates and NOT gates The basic logic gate whose output is the complement of the input is the ______a) OR gate b) AND gate c) INVERTER gate d) XOR gate If we use an AND gate to inhibit a signal from passing one of the inputs must be ______a) LOW b) HIGH c) Inverted d) Floating