Sie sind auf Seite 1von 6

Types of binary codes

Binary codes are codes which are represented in binary system with modification from
the original ones. Below we will be seeing the following: Weighted codes and Non-
Weighted codes Weighted binary codes Weighted binary codes are those which obey
the positional weighting principles, each position of the number represents a specific
weight. The binary counting sequence is an example.

Decimal 8421 2421 5211 8 4 -2 -1 6 4 2 -3 Excess-3


0 0000 0000 0000 0000 0000 0011
1 0001 0001 0001 0111 0101 0100
2 0010 0010 0011 0110 0010 0101
3 0011 0011 0101 0101 1001 0110
4 0100 0100 0111 0100 0100 0111
5 0101 1011 1000 1011 1011 1000
6 0110 1100 1010 1010 0110 1001
7 0111 1101 1100 1001 1101 1010
8 1000 1110 1110 1000 1010 1011
9 1001 1111 1111 1111 1111 1100

8421 code/BCD code


The BCD (Binary Coded Decimal) is a straight assignment of the binary equivalent. It is
possible to assign weights to the binary bits according to their positions. The weights in
the BCD code are 8,4,2,1.
Example: The bit assignment 1001, can be seen by its weights to represent the decimal
9 because 1x8+0x4+0x2+1x1 = 9

2421 code
This is a weighted code; its weights are 2, 4, 2 and 1. A decimal number is represented
in 4-bit form and the total four bits weight is 2 + 4 + 2 + 1 = 9. Hence the 2421 code
represents the decimal numbers from 0 to 9.

5211 code
This is a weighted code; its weights are 5, 2, 1 and 1. A decimal number is represented
in 4-bit form and the total four bits weight is 5 + 2 + 1 + 1 = 9. Hence the 5211 code
represents the decimal numbers from 0 to 9.

Representation of some decimal numbers are not unique .

In (2,4,2,1) code, decimal 7 may be represented by


1101 and 0111

Self-Complementing Codes
A code is said to be self-complementing if the code word of 9’s complement of N i.e. 9 –
N, can be obtained from the code word of N by interchanging all the 1’s and 0’s.
Eample : In (642-3) code
 decimal 3 is represented by 1001, while decimal 6 is represented by 0110.

 decimal 2 is represented by 0010, while decimal 7 is represented by 1101.

BCD code is not self-complementing


Important
A necessary condition for weighted coders to be self-complementing is that sum of the
weights must be equal to 9. There exists only four positively weighted self-
complementing codes viz (2421), (3321), (4311), 5211).

Reflective code
A code is said to be reflective when code for 9 is complement for the code for 0, and so
is for 8 and 1 codes, 7 and 2, 6 and 3, 5 and 4. Codes 2421, 5211, and excess-3 are
reflective, whereas the 8421 code is not.

Sequential code
A code is said to be sequential when two subsequent codes, seen as numbers in
binary representation, differ by one. This greatly aids mathematical manipulation of
data. The 8421 and Excess-3 codes are sequential, whereas the 2421 and 5211 codes
are not.

Non-Weighted code
Non weighted codes are codes that are not positionally weighted. That is, each position
within the binary number is not assigned a fixed value.

Excess-3 code
Excess-3 is a non weighted code used to express decimal numbers. The code derives
its name from the fact that each binary code is the corresponding 8421 code plus
0011(3). Example: 1000 of 8421 = 1011 in Excess-3

Gray code
The Gray code was designed by Frank Gray at Bell Labs, patented the code in 1947.
The gray code belongs to a class of codes called minimum change codes, in which only
one bit in the code changes when moving from one code to the next. 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. This is also called a unit-distance code. In digital
Gray code has got a special place. It is an unweighted binary code in which two
successive values differ only by 1 bit. Owing to this feature, the maximum error that can
creep into a system using the binary Gray code to encode data is much less than the
worst-case error encountered in the case of straight binary encoding. Table 2.3 lists the
binary and Gray code equivalents of decimal numbers 0–15.

An examination of the four-bit Gray code numbers, as listed in Table below, shows that
the last entry rolls over to the first entry. That is, the last and the first entry also differ by
only 1 bit. This is known as the cyclic property of the Gray code. Although there can
be more than one Gray code for a given word length, the term was first applied to a
specific binary code for non-negative integers and called the binary-reflected Gray
code or simply the Gray code.

Decimal Number Binary Code Gray Code


0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000

Binary–Gray Code Conversion


A given binary number can be converted into its Gray code equivalent by going through
the following steps:
 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 number.
 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 (modulo 2 sum), if any. That is, if the MSB and the bit
adjacent to it are both ‘1’, then the corresponding Gray code bit would be a ‘0’.
 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.
 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 : showing step-by-step conversion of (1011)2 into its Gray code equivalent:

Binary 1011
Gray code 1- - -
Binary 1011
Gray code 11- -
Binary 1011
Gray code 111-
Binary 1011
Gray code 1110

Gray Code–Binary Conversion

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

 Begin with the most significant bit (MSB). The MSB of the binary number is the
same as the MSB of the Gray code number.
 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(modulo 2 sum), if any.
 The third MSB in the binary number is 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 ignored.
 The process continues until we obtain the LSB of the binary number.

Example : step-by-step conversion of the Gray code number 1110 into its binary
equivalent:

Gray code 1110


Binary 1- - -
Gray code 1110
Binary 10 - -
Gray code 1110
Binary 101
Gray code 1110
Binary 1011

Error detecting and correcting codes


For reliable transmission and storage of digital data, error detection and correction is
required. Below are a few examples of codes which permit error detection and error
correction after detection.
Error detecting codes
When data is transmitted from one point to another, like in wireless transmission, or it is
just stored, like in hard disks and memories, there are chances that data may get
corrupted. To detect these data errors, we use special codes, which are error detection
codes.

Parity bit
In parity codes, every data byte, or nibble (according to how user wants to use it) is
checked if they have even number of ones or even number of zeros. Based on this
information an additional bit is appended to the original data. Thus if we consider 8-bit
data, adding the parity bit will make it 9 bit long. At the receiver side, once again parity
is calculated and matched with the received parity (bit 9), and if they match, data is ok,
otherwise data is corrupt.

Two types of parity


Even parity: Checks if there is an even number of ones; if so, parity bit is zero.
When the number of ones is odd then parity bit is set to 1.

Odd Parity: Checks if there is an odd number of ones; if so, parity bit is zero. When
number of ones is even then parity bit is set to 1.

Error correcting codes


Error-correcting codes not only detect errors, but also correct them. This is used
normally in Satellite communication, where turn-around delay is very high as is the
probability of data getting corrupt.

Hamming codes
Hamming code adds a minimum number of bits to the data transmitted in a noisy
channel, to be able to correct every possible one-bit error. It can detect (not correct)
two-bit errors and cannot distinguish between 1-bit and 2-bits inconsistencies. It can't -
in general - detect 3(or more)-bits errors.

Alphanumeric codes
The binary codes that can be used to represent all the letters of the alphabet, numbers
and mathematical symbols, punctuation marks, are known as alphanumeric codes or
character codes. These codes enable us to interface the input-output devices like the
keyboard, printers, video displays with the computer.
ASCII codes
ASCII stands for American Standard Code for Information Interchange. It has become a
world standard alphanumeric code for microcomputers and computers. It is a 7-bit code
representing 27 = 128 different characters. These characters represent 26 upper case
letters (A to Z), 26 lowercase letters (a to z), 10 numbers (0 to 9), 33 special characters
and symbols and 33 control characters.

EBCDIC codes
EBCDIC stands for Extended Binary Coded Decimal Interchange. It is mainly used with
large computer systems like mainframes. EBCDIC is an 8-bit code and thus
accommodates up to 256 characters. An EBCDIC code is divided into two portions: 4
zone bits (on the left) and 4 numeric bits (on the right).

Das könnte Ihnen auch gefallen