Binary Code- Binary Code, Gray Code, Excess 3 Code Explained

Binary Code This chapter is an extension of the previous chapter about the digital system. The previous chapter, starting with some basic concepts common to all number systems and an overview of familiar decimal number systems.

we continued to discuss binary, hexadecimal and octal number systems. Binary Code Although the binary representation system is the most widely used system in digital systems, the octal and hexadecimal systems are often used to represent groups of binary numbers.

The Binary Code encoding system discussed in the previous chapter becomes very troublesome when used to represent large decimal numbers.

In order to overcome this shortcoming and perform many other special functions, several binary codes have been developed over the years.

Binary Code This chapter will detail some of the more well-known binary codes, including those that are effectively used to represent numeric and alphanumeric data, and codes that perform special functions.

Binary Code Decimal

Binary Coded Decimal (BCD) is a binary code used to represent a given decimal number in its equivalent binary form. The conversion from BCD to decimal and decimal to BCD is very easy and straightforward.

It is much more troublesome to represent a given decimal number in the equivalent BCD code than in the equivalent direct binary form discussed in the previous chapter.

Write the BCD equivalent to the decimal number by replacing each decimal digit in the integer part and the decimal part with its four-digit binary equivalent.

For example, the BCD equivalent to (23.15) 10 is written as (0010 0011.0001 0101) BCD. The above-mentioned BCD code is more accurately called the 8421 BCD code, where 8, 4, 2, and 1 represent the weights of different bits in the four-bit group, starting from the MSB and proceeding toward the LSB.

Binary Codes
Binary Coded Decimal

This feature makes it a weighted code, which means that each of the four digits representing a given decimal number is assigned a weight.

Other weighted BCD codes include 4221 BCD and 5421 BCD codes. Similarly, 4, 2, 2, and 1 in the 4221 BCD code and 5, 4, 2, and 1 in the 5421 BCD code represent the weights of the relevant bits.

BCD-to-Binary Conversion

A given BCD number can be converted to an equivalent binary number by first writing its decimal equivalent, and then converting it to a binary equivalent.

The first step is simple, and the second step has been explained in the previous chapter. For example, the binary equivalent of the BCD number 0010 1001.0111 0101.

  • BCD number: 0010 1001.0111 0101.
  • Corresponding decimal number: 29.75.
  • Therefore, (0010 1001.0111 0101)BCD = (11101.11)2

Binary To BCD Conversion

The conversion process from binary to BCD is the same as the conversion process from BCD to binary performed in the reverse order.

By first determining the decimal equivalent value, and then writing the corresponding BCD equivalent value, the given binary number can be converted into an equivalent BCD number.

For example, we will find the BCD equivalent of the binary number 10101011.101.

  • The decimal equivalent of this binary number can be determined to be 171.625.
  • The BCD equivalent can then be written as 0001 0111 0001.0110 0010 0101.

Higher Density BCD Encoding

In the conventional BCD encoding of decimal numbers, the number of digits required to represent a given decimal number is always greater than the number of digits required for direct binary encoding.

For example, a three-digit decimal number requires 12 digits to be represented in the regular BCD format. However, due to 210103, if these three decimal digits are coded together, only 10 digits are required.

Two such coding schemes are Chen-Ho coding and densely packed decimal.

The advantage of the latter is that, like regular BCD, the encoded subset encodes two bits with the best 7 bits and one bit with 4 bits.

Packed and Unpacked BCD Numbers

For unpacked BCD numbers, each four-digit BCD group corresponding to a decimal number is stored in a separate register inside the machine.

In this case, if the register is eight bits or wider, the register space is wasted. For packed BCD numbers, two BCD numbers are stored in a single 8-bit register.

The process of combining two BCD numbers to store them in an eight-bit register involves moving the number in the upper register 4 times to the left and then. This process is illustrated by displaying the storage of decimal numbers 5and 7.

Also Read: Clipper Circuit: positive, Double & problems Explained

Excess 3 Code

This is particularly important for arithmetic operations because it overcomes the shortcomings encountered when using the 8421 BCD code to add two decimal numbers whose sum exceeds 9.

The extra 3 codes do not have this restriction and greatly simplify arithmetic operations. Table 2.2 lists the extra 3 codes, decimal digits 0-9.

The extra 3 codes of a given decimal number are obtained by adding “3” to each decimal digit of the given number and then using

Excess 3 Code
Excess 3 Code

Its four-digit binary equivalent value. What may be mentioned here is that if adding “3” to a number will produce a carry, just like the numbers 7, 8, and 9, then the carrier should not be postponed.

The result of the addition should be regarded as a whole, and then replaced with the equivalent extra 3 codes. For example, let us find the extra 3 digits of the decimal number 597.

In general, the usual practice is to use the largest number of digits that the number system can handle to represent a given decimal number or number.

For example, in four-digit decimal arithmetic, 5 and 37 will be written as 0005 and 0037, respectively. The corresponding 8421 BCD equivalents will be 0000000000000101 and 0000000000110111, and the equivalents of more than 3 codes will be 0011001100111000 and 0011001101101010.

Corresponding to the given extra 3 codes, the equivalent decimal number can be determined by first dividing the number into four digits, starting from the decimal point, and then subtracting 0011 from every four digits.

The new number is the 8421 BCD equivalent of the given Extra-3 code, which can then be converted to an equivalent decimal number.

For example, following the steps below, the decimal equivalent of the number 01010110.10001010 with more than 3 is 23.57.

Another important feature that makes this code attractive for performing arithmetic operations is that the extra 3 digits of a given decimal number produce an extra 3 digits of the decimal 9’s complement.

When adding the 9’s complement of decimal number B to decimal number A to get A-B, the extra 3 codes can be effectively used for addition and subtraction of decimal numbers.

Also Read: Clamper circuits – Positive clamper, Negative clamper Explained

Gray Code

The Gray code was designed by Frank Gray of Bell Labs and patented in 1953. It is an unweighted binary code in which two consecutive values ​​differ by only 1 bit.

Because of this feature, the maximum error that can penetrate the system when using binary Gray code to encode data is much smaller than the worst-case error encountered in the case of direct binary encoding.

The table lists the binary and gray codes of the equivalent decimal numbers 0-15. As shown in Table 2.3, the inspection of the four-digit Gray code shows that the last entry will scroll to the first entry.

In other words, the difference between the last entry and the first entry is only 1 bit. This is called the cyclic property of the Gray code.

Binary Code

There are many ways to remember the Gray code with a given number of positions. One such way is to remember that the least significant bit follows repeat pattern 2, the next higher adjacent bit follows pattern 4, and so on.

We can also recursively generate n-bit Gray codes by adding 0 to the gray code of n -1 bits to obtain the first 2n-1 digits, and then adding 1 to the reflected Gray code of n -1 bits to obtain n- 1 person.

The remaining 2n-1 numbers. The reflected Gray code is nothing more than code written in reverse order. The table illustrates the process of using reflection and prefix methods to generate high-level Gray codes.

The bit column between the bits representing the Gray code gives an intermediate step, which is to write the code and then write it in the reverse order.

Binary Gray Code Conversion

Binary Gray Code Conversion. Binary words are strings that can be converted into binary codes. For example, the word “green” could be represented in binary code as “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ”.

Unlike ASCII codes, these are not human readable, so the function output each 0 or 1 instead of letters or numbers. If the binary code does not satisfy the initial conditions, an error will be reported.

The code you enter is compared to the library’s (e.g., GNU Octave) internal function to determine if the value matches.

Gray Code Binary Conversion

The following steps will convert a given Gray code number into its binary equivalent.

  • 1. Start with the most important bit (MSB). The binary number’s MSB is identical to the Gray code number’s MSB.
  • 2. By inserting the Binary number MSB in a second MSB in the Gray code number and, if any, not considering the carry, the bit next to MSB (second MSB) is generated in the binary number.
  • 3. A second MSB in the binary number is added to the third MSB in a grey code number by inserting a second MSB in a binary number. Carry is to be forgotten again if any.
  • 4. This procedure goes on until the binary number’s LSB is obtained.

n ary Gray Code

The above-mentioned binary-reflected grey code still is called the ‘Gray Code.’

In the course of the years, however, other forms of grey code have been identified.

One such code is the n-ary Gray code which is also known as the non-Boolean Gray code because of non-Boolean symbols. Encoding.

The widespread representation of the code is (n, k jusqu’à grey code where n The word length is used with independent numbers and k.

Gray ternary codes (n = 3) use 0, A two-digit word length will include 1 and 2, and number series (00, 01, 02, 12, 11, 10,21, 22).

The sequence of numbers will be in the quaternary (n=4) code, using 0, 1, 2, and 3 as independent numbers and a two digit word length (00, 01, 02, 03, 13, 12, 11, 10, 20, 21, 22, 23, 33, 32, 31, 30).

It should be noted that an (n, k TEG-Gray code with an odd n does not show the cyclic property of the binary Grey code but has the cyclic property in the event of even n.

The (n, k-family-gray code, like the binary-reflected grey code, can be recourse-built, or iteratively constructed.

The table shows the way to generate larger term grey codes. The columns between the ternary grey ones are the intermediate steps.


  • 1.The Gray code is used for digital signal transmission because it minimizes errors.
  • 2. Gray coding in angle measurement units is preferred over straight binary code. Usage of the grey code almost removes the chance of misreading the angle, probably if the angle is displayed in straight binary. An advantage of this application is the cyclical feature of the Gray code.
  • 3. The grey code is used to mark the Karnaugh map axes, the graphic form used to minimize Boolean expressions.
  • 4.Gray codes are used in computers to address program memory, reducing power consumption. This is due to fewer address lines shifting state as the software counter progresses.
  • 5.Gray codes are also useful in genetic algorithms since mutations in the code allow for mostly gradual changes. However, every now and then, a single bit shift will trigger a huge leap, resulting in new properties.

Also Read: Full-wave rectifier & Bridge Rectifier


Who invented binary and balance system

The modern binary number scheme can be traced back to Gottfried Leibniz, who suggested and created it in his 17th-century essay Explication de l’Arithmétique Binaire . Leibniz devised the method in 1679, but it was not written until 1703.

Why computers only use binary language even after technology developments

This day, a computer stores data using other advanced techniques and technology. Binary coding is made up of just 1’s and 0’s, but it can also represent the most sophisticated programming programs today.

YouTube Video

Continue Reading..

Leave a Comment