Codigo 4221
Codigo 4221
Codigo 4221
The usual way of expressing a decimal number in terms of a binary number is known
as pure binary coding and is discussed in the Number Systems section. A number of
other techniques can be used to represent a decimal number. These are summarised
below.
In the 8421 Binary Coded Decimal (BCD) representation each decimal digit is
converted to its 4-bit pure binary equivalent.
Addition is analogous to decimal addition with normal binary addition taking place from
right to left. For example,
Where the result of any addition exceeds 9(1001) then six (0110) must be added to the
sum to account for the six invalid BCD codes that are available with a 4-bit number.
This is illustrated in the example below
Note that in the last example the 1 that carried forward from the first group of 4 bits has
made a new 4-bit number and so represents the "1" in "15".
In the examples above the BCD numbers are split at every 4-bit boundary to make
reading them easier. This is not necessary when writing a BCD number down.
This coding is an example of a binary coded (each decimal number maps to four bits)
weighted (each bit represents a number, 1, 2, 4, etc.) code.
Gray Code
Gray coding is an important code and is used for its speed, it is also relatively free from
errors. In pure binary coding or 8421 BCD then counting from 7 (0111) to 8 (1000)
requires 4 bits to be changed simultaneously. If this does not happen then various
numbers could be momentarily generated during the transition so creating spurious
numbers which could be read.
Gray coding avoids this since only one bit changes between subsequent numbers. To
construct the code there are two simple rules. First start with all 0s and then proceed
by changing the least significant bit (lsb) which will bring about a new state.
1. The binary number and the Gray-coded number will have the same number of
bits
2. The binary MSB (left-hand bit) and Gray code MSB will always be the same
3. To get the binary next-to-MSB (i.e. next digit to the right) add the binary MSB
and the gray code next-to-MSB. Record the sum, ignoring any carry.
4. Continue in this manner right through to the end.
An example of converting a gray code number to its pure binary equivalent is available
in the Solved Problems