Binary Codes Logic Gate & Boolean Algebra by Ratnesh
Total Page:16
File Type:pdf, Size:1020Kb
Binary Codes Logic Gate & Boolean algebra 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 binary number greater than its preceding code. This property helps in manipulation of data. 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 bits. As per the weighted binary digits, the 4 Bit 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.