Codes:-Symbolic representation of discrete information may be number,letters etc is known as code.
code are used to enable an operator to feed data directly into the computer.
Binary Codes:– The process of converting data into binary format is known as binary coding. the combination of binary bits that represent numbers,alphabets,symbols or control function are called binary codes.
Advantage of Binary Codes:-
- Implementation is easy because it uses 0 and 1.
- Suitable for the computer application.
- Binary codes make the analysis and designing of digital circuits if we use the binary codes.
Application of Binary Codes:-
- In digital computer
- in digital communication
Classification of Binary codes:-
- weighted codes
- Non-weighted codes
- Reflective codes
- Sequential codes
- Alphanumeric codes
- Error detecting and correcting codes
Weighted code:- the main characteristics of a weighted code is each binary bit is assigned by a weight and values depend on the position of binary bit.
If w1 , w2 , w3 , w4 are the weights of the binary digits and b1 , b2 , b3 and b4 are the corresponding bit values then the decimal digit
N = w4b4 + w3b3 +w2b2 + w1b1
b4b3b2b1 is code word.
Example of weighted code- BCD, 8421, 2421, 5421, 84-2-1 etc..
Non-weighted code:- Non-weighted codes or unweighted codes are those codes in which the digit value does not depend upon this position. It means each digit position within the number is not a fixed value.
Example:- Unweighted BCD code, Excess-3 and Gray code.
Comparison between weighted and non-weighted codes:-
Reflective Codes:- A cide is said to be reflective, when the code for 9 is the complement for 0, code for 8 is complement for 1, 7 for 2, 6 for 3 and 5 for 4.
Reflective is desirable in a code when the 9’s complement is required to be found e.g. in 9’s complement subtraction.
2421,5211 and XS-3 are the examples of reflective codes.
Sequential Codes:- A code is said to be sequential when each succeeding code is one binary number greater than the preceding code. this greatly simplifies the mathematical manipulations. the 8421 and XS-3 are sequential codes.
Alphanumeric Codes:- The alphanumeric codes are design to represent number as well as alphabetic characters. some of these codes are capable to representing some symboles and instructions as well.
Example of Alphanumeric codes are :- ASCII ( American Standard Code for Information Interchange ), EBCDIC ( Extended Binary Coded decimal Interchange Code ) and Hollerith Code.
Error Detecting and Correcting Code:- When digital data or information is transmitted from one system (such as a computer) to the other, an unwanted electrical disturbance called “Noise” gets added to it. The noise can force an “error” in the digital information . that means a 0 may change to 1 or 1 may change to 0.
To detect and correct such error we can use some special codes which process the capacity to detect and correct the error. such codes are called as error detecting and correcting codes.
Binary Coded Decimal (BCD) Code- BCD is the short form of “Binary Coded Decimal”. In this code each decimal number is represented by 4-bit binary number.Since a decimal digit can be as large as 9, four bits are required to code each digit.
Conversion from decimal to BCD:- the decimal digits 0 to 9 are converted into a BCD, exactly in the same way as binary.
Example:- Take a decimal number as 874. Each digit is changed to its binary equivalent as follows:
BCD Addition:- The following steps are followed
- Add two 4 bit BCD number using straight binary addition
- If 4 bit Sum <= 9. The Sum is a valid BCD number and no correction is needed.
If the 4 bit Sum > 9 or if a carry is generated from the Sum is in valid BCD number. then, the digit 6 ( 0 1 1 0) should be added to the Sum to produce the valid BCD symbols.
BCD Subtraction:- The subtraction of two BCD numbers A and B can be performed using one of the following method.
- 9’s complement
- 10’s complement
BCD Subtraction using 9’s complement:-
- obtain the 9’s complement of no. B
- Add A and 9’s complement B.
- If a carry is generated in step 2 then add it to the sum to obtain the final result.
- If carry is not produce then the result is -ve hence take the 9’s complement of the result.
Example 1:- Subtract (3 )10 from (7)10 in BCD
Step 1 : obtain 9’s complement of (3)10
9 – 3 = 6
Step 2 : Add 7 and 9’s complement of 3
7 + 6 = 13
Step 3 : If a carry is generated in step 2 then add it to the sum to obtain the final result.
so 3 + 1 =4
Answer : 4
Example 2 :– perform the subtraction (4)10 – (7)10 using 9’s complement in BCD.
Step 1: obtain the 9’s complement of no. B
9 – 7 = 2
Step 2: Add A and 9’s complement B.
Subtraction using 10’s complement: The 10’s complement is obtained by adding 1 to the 9’s complement.
Step 1: Obtain the 10’s complement of subtrahend.
Step 2: Add the minuend to the 10’s complement of subtrahend.
Step 3: Discard carry. If carry is 1 then the answer is positive and in its true form.
Step 4: If carry is not produced then the answer is negative. So take 10’s complement to get the answer.
Example:- Perform the subtraction (9)10 – (4)10 in BCD using the 10’s complement.
Solve:- Obtain the 10’s complement of (4)10
9’s complement of (4)10 = 9 -4 = 5
10’s complement of (5)10 = 5 + 1 = 6
Step2:- Add (9)10 and 10’s complement of (4)10
(9)10 1 0 0 1
(6)10 0 1 1 0
Signed-Magnitude BCD Numbres:-
The representation of signed decimal number in BCD is similar to the representation of signed number in binary.It is possible to use either the sign magnitude system or signed-complement system.The sign of a decimal number is generally represented with four bits. The plus sign is denoted by four zeros and minus with the BCD equivalent of 9 i.e. 1001.
Example 1:- Represent the numbers +25 and -25 in the signed magnitude form.
Signed-Complement BCD Numbers:– The signed magnitude system is generally not used in computers. The signed complement system can be either the 9’s complement,but the 10’s complement is the most preferred one. The procedure developed for the signed 2’s complement system is also applicable to the signed 10’s complement system for decimal numbers.
Represent +420 and -420 in the signed complement form.
Representation of +420:
Other 4 bit weighted Decimal codes: less than 5 give preference to LSB and larger than 5 give preference to MSB.
Example1:- Construct a table for a 5321 weighted code and write 9371 using this code.
Example2:- Construct a table for 4321 weighted code and write 6472 using this code.
Non-Weighted Codes:- Non-weighted codes do not have any positional weight attached to them.
Example of non-weighted code.
1. Excess-3 code
2. Gray code
1.Excess-3 code:- Excess-3 code is modified form of BCD code. The Excess-3 code can be obtained from the natural BCD code by adding 3 to each coded number.
It is called (XS-3 or Ex-3 c0de).
Gray Code:- the code which exhibits only a single bit change from one number to the next is known as Gray Code. i.e. in this code between any two successive code words,there will be change in only one position. this code is also called as “Unit Distance Code.” or “Reflected Code”. As there is no specific weight assigned to each bit position, So this code is Non-weighted code.
Cyclic Code:- A Code which has one bit change in successive code words, is called as a cyclic code. A particular important cyclic code is Gray Code.
Gray to Binary Conversion:- For converting Gray Code to Binary following rules apply:
1. the most significant bit (MSB) in the binary code is the same as the corresponding digit in Gray Code.
2. Add each binary digit generated to the Gray digit in the next adjacent position. Discard carries
3. Continue this process until the LSB is reached.
The Gray Code number 1 1 0 1 0 can be converted to binary as follows:
Alphanumeric Codes:- Digital systems are required to handle data which may be letters,numbers or special characters. the computer or digital systems should recognise the codes that represent these alphanumeric data.These codes are known as alphanumeric codes. the following codes come under this category.
1.ASCII Code: this is most widely used alphanumeric code in computer. this is also known as American Standard Code for information Interchange. the ASCII code is 7 bit code and can represent 27 = 128 possible characters.
2. EBCDIC Ciode:- This code is known as Extended Binary Coded Decimal Interchange Code. this is an 8 bit Code.