Menu

Thursday 5 February 2015

Introduction To Digital Electronics and Logic (Chapter 2: Binary Codes)



2.1 Binary Codes
While the binary system of representation is the most extensively used one in digital systems, including computers, octal and hexadecimal number systems are commonly used for representing commonly used for representing groups of binary digits. The binary coding system, called the straight binary code and discussed earlier, becomes very cumbersome to handle when used represent larger decimal number.
To overcome this shortcoming and also to perform may other special functions, several binary codes have evolved over the years.  
We now know that computers and other digital systems “work” with binary numbers. Input and output is usually done using decimal numbers, alphabetic and special symbols, Computer system has to device a way of representing alphanumeric with binary numbers, these representations are called codes.
These codes are used to effectively represent numeric and alphanumeric data and the codes used to perform special functions, such as detection and correction or errors. 

Classification of binary codes

·        Weighted code

·        Non-weighted code
Weighted Code: are binary code which obey the positional weighted principle. Each position of number represents a specific weight e.g. BCD, straight binary.
Non-weighted code; here the positional weights are not assigned. The example of non-weighted codes are, Excess-3 code and Gray code. 

2.2  Binary Coded Decimal (BCD)4
BCD is a type of binary code used to represent a given decimal number in an equivalent binary form. BCD-to-decimal and decimal-to-binary is far less cumbersome than straight binary representation and conversion.
The BCD equivalent of a decimal number is written by replacing each decimal digit in the integer and fractional parts with the four-bit binary equivalent. In decimal, there can be not single digit that will have value more that ‘9’, thus binary representation beyond ‘9’ is not useable in BCD. See table 2.1.


Table 2.1:  Four bit equivalent of decimal 0 – 15.
 















We will best explain the process of BCD-to-decimal conversion and vice versa with examples.

Decimal-to-BCD
Example 2.1:
Convert (23.25)10 into binary coded decimal.





Answer: (23.25)10 = (0010001100100101)BCD

Example 2.2: 
(968.02) =  ?BCD
 






 Answer: (23.25)10 = (0010001100100101)BCD

Example 2.2: 
(968.02) =  ?BCD
 





BCD-to-Decimal
Example 2.3
(101001.011101)BCD = ?10







Answer : (101001.011101)BCD = 29.7410

Binary coded decimal can be converter to straight binary by firs converting it to decimal and from decimal to straight binary for example;

Example 2.4
            (10001001.00010101)BCD  =  ?2






          =   (89.15)10
To convert the decimal result to binary we have;











=   (1011001)2
  
Fractional part:  0.15



  


=  (001001…)2


Answer: 1011001.0010012



2.3  Excess – 3 Code5
The excess-3 code is another important binary code. It is particularly significant for arithmetic operations as it overcomes the shortcomings encountered while using the BCD code to add two decimal digits whose sum exceed 9.
The excess-3 code has no such limitation and it considerably simplifies arithmetic operations.
The excess-3 code for a given decimal number is determined by adding ‘3’ to each decimal digit in the given number and then replacing each digit of the newly found decimal number by its four-bit equivalent.
It may be mentioned here that, if the addition of ‘3’ to a digit produce a carry as is the case with the digit 7, 8, and 9, that carry should not be taken forward. The result of addition should be taken as a single entity and subsequently replaced with its excess-3 code equivalent.

Example 2.4:
Find excess-3 code for the decimal number 597.

            (5+3)   (9+3)   (7+3)
              ‘8’      ‘12’      ‘10’
            1000   1100     1010

Answer: (595)10  =   (1000 1100 1010)Ex-3

Example 2.5
 Convert  (0101 0111 0011.1000 1001)Excess-3 to decimal number.
 






Answer: (0101 0111 0011.1000 1001)Excess-3 = (240.56)10

2.4.  Gray Code6

The gray code was designed by Frank Gray at Bell labs and patented in 1953. It is an unweighted binary code with successive values only differs by 1 bit.
Using gray code to design a digital system, we can leverage on this property to provide data integrity, in that it may allow lesser error than straight binary coding. 

Binary-to-Gray Code Conversion
A given binary number can be converted into its gray code equivalent by going through the following steps;
i.   Begin with the most significant bit (MSB) of the binary number; the MSB of the gray code equivalent is the same as the MSB of the given binary.
ii. The second most significant bit, adjacent to the MSB, in the gray code number is obtained by adding the MSB and the second MSB of the binary number and ignoring the carry, if any. I.e. if the MSB and the bit adjacent to it are both ‘1’, the corresponding gray code bit would be a ‘0’.
iii. The third most significant bit, adjacent to the second MSB, in the gray code number is obtained by adding the second MSB and the third MSB in the binary number and ignoring the carry, if any.
iv.  The process continues until we obtain the LSB of the gray code number by the addition of the LSB and the next higher adjacent bit of the binary number.

Example 2.6:
Convert (1011)2 to gray code
 


  




Answer: (100101)2 = (110111)gray



Gray-to-binary
A given gray code number can be converted into its binary equivalent by going through the following steps:

i.                    Beginning with the most significant bit (MSB). The MSB of the binary number is the same as the MSB of the gray code number.
ii.                 The bit next to the MSB (the second MSB) in the binary number is obtained by adding the MSB in the binary number to the second MSB in the gray code number and disregarding the carry, if any.
iii.               The third MSB in the binary number obtained by adding the second MSB in the binary number to the third MSB in the gray code number. Again, carry, if any is to be disregarded.
iv.               The process continues until we obtain the LSB of the binary number.

Example 2.8:
Convert gray code number 1110gray to binary equivalent.

 


Answer: (1110)gray = (1011)2

Example 2.9: 
Convert gray code number 1010gray to binary equivalent.
 






Answer: (1010)gray = (1100)2

Applications of Gray Code
i.                    For transmission of digital signal as it minimizes error.
ii.                 The gray code is preferred over the straight binary code in angle measuring devices. Use of the gray code almost eliminate the possibility of an angle misread, which is likely of the angle is represent in straight binary. The cyclic property of the gray code is a plus in this application.
iii.               The gray code is used for labeling the axis of karnaugh maps, a graphical techniques used for minimizing Boolean expression.
iv.               The use of gray codes to address program memory in computers minimizes power consumption. The is due to fewer address line changing.
v.                  Gray code is also very useful in genetic algorithms since mutations in the code allow for mostly incremental changes.

2.5  Seven Segment display Code7
Seven Segments display are very common and are found almost everywhere, e.g. pocket calculators, digital clocks, electronic test equipments, petrol pumps.
We have the Light emitting diode (LED) 8 type and Liquid Crystal Display (LCD)9 types of seven-segment display. Also we categorize seven-segment display into; (i) Common-cathode (ii) Common-anode.


Figure 2.1: Seven-Segment LED.



Figure 2.2: (a) Common-cathode9 circuit configuration of seven-segment display (b) common-anode10 circuit configuration of seven-segment display.
 This kind of display is employed to display numerals from 0-9 and letters from A to F. In common-cathode type ‘1’ mean ‘ON’ and ‘0’ means off while in common-anode ‘0’ means ‘ON’ and ‘1’ means off.


Seven Segment Display Code6


2.6  Other Useful binary Codes in Digital System
Error Detection and Correction Code
Error detection and correction code are of great importance in digital system. Noise or other impairments during the course of conveying data information from the transmitter to the receiver introduces error into the system.
Due to its sensitivity to errors, digital systems tend to malfunction if the bit error rate is more than a certain threshold level. This makes it paramount to device a means of detecting and correcting occurrence of error in the system.
Error detection and correction coding involves the addition of extra bits, called check bits, to the information-carrying bit stream to give the resulting bit sequence a unique characteristics that helps in detection and localization of errors.
These additional bits are also called redundant bit as they do not carry any information. Types of error detection/correction codes are;
i.                    Parity code12 (even or odd)
ii.                 Repetition code15
iii.               Cyclic redundancy check13 code
iv.               Hamming code14

Alphanumeric codes11
These are binary code used to represent alphanumeric data. Also called character code, it is used to write alphanumeric data which includes letters of alphabet, numbers, mathematical symbols and punctuation marks, in a form that is understandable and can be processed by a computer. It is a useful code in interfacing input-output devices such as keyboards, printers, Joystick, Video Display Unit (VDUs19) e.t.c, with the computer. Examples of alphanumeric codes are;
i.                    American Standard Code for Information Interchange (ASCII16).
ii.                 Extended Binary Coded Decimal Interchange Code (EBCDIC17).
iii.               Unicode and ISO-10646 Standards18







No comments:

Post a Comment

Please drop your comment here, thanks.