Skip to content

VLSIFacts

Let's Program the Transistors

  • Home
  • DHD
    • Digital Electronics
    • Fault Tolerant System Design
    • TLM
    • Verification
    • Verilog
    • VHDL
    • Xilinx
  • Embedded System
    • 8085 uP
    • 8086 uP
    • 8051 uC
  • VLSI Technology
    • Analog Electronics
    • Memory Devices
    • VLSI Circuits
  • Interview
    • Interview Experience
    • Training Experience
    • Question Bank
  • Notifications
  • QUIZ
  • Community
  • Job Board
  • Contact Us
  • Toggle search form

Hamming Codes

Posted on March 20, 2023June 19, 2025 By vlsifacts No Comments on Hamming Codes

Hamming Code is yet another error detection and correction code. In this code, the parity bits are added to increase the Hamming distance between the valid code words. Here, the parity bits are arranged in a way that different error bits produce different error results. This enables the Hamming Code to both detect and localize the error bit.

Number of Parity bits in Hamming Code

The most popular Hamming code is Hamming (7,4) code. In this code, the length of the code word c = 7, the number of data bits (information bits) d = 4, and the number of parity bits (check bits) p = 3. So, in a Hamming code, if the number of parity bits is ‘p’, then the length of the code word can be a maximum of c = 2p – 1; and the number of data bits can be a maximum of d = 2p – 1 – p.

Therefore, the number of parity bits p required to encode d data bits is the smallest integer that satisfies the condition (2p – p) > d.

Rules of Hamming Code

Since Hamming (7,4) is the most popular one, we will understand the rules of Hamming code keeping Hamming (7,4) code in mind.

1. The Hamming code is represented in the following form:

Representation of Hamming Code

Here, P represents parity bits, and D represents data bits.

2. All the bit positions that are the power of 2 (e.g. 20, 21, 22, 23, …) are occupied by the parity bits.

3. Remaining bit positions (e.g. 3, 5, 6, 7, …) are used for data bits.

According to points 1 to 3, for Hamming (7,4) code, the representation will be: P1P2D1P3D2D3D4

4. Each parity bit is assigned a group of data bits that decide the value of the parity bit according to the type of parity used.

5. To form the group for a parity bit, the corresponding parity bit and the bits following the parity bit in the code word are considered. The group is formed by adding the first N-1 bits and then alternately skipping and adding N bits following the parity bit. N is the position of the parity bit (e.g. 1 for P1, 2 for P2, 4 for P3 and so on).

According to points 4 and 5, for Hamming (7,4) code, the groups for the parity bits are as follows:
P1: D1D2D4 ; P2: D1D3D4 ; P3: D2D3D4
Let’s clarify the process by considering P2
For constructing the group for P2 we will take the bits after P2 : D1P3D2D3D4
Here, N = 2
First taking N-1 bits, that means taking 2-1 = 1 bit, which is taking D1
Then skipping N bits; means skipping 2 bits, which is skipping P3D2
Then taking N bits; means taking 2 bits, which is taking D3D4
Thus, the group of bits to decide the value of P2 is D1D3D4

Generation of Hamming code

Now, we will compute the even parity bits for an example, 4-bit data bits “1001” and the complete Hamming (7,4) code word.

 P1P2D1P3D2D3D4
Only data bits  1 001
Data bits and P10 1 001
Data bits and P2 01 001
Data bits and P3  11001
Code word0011001

An Example Case of Error Detection and Correction

Here, we will consider the above code word: P1P2D1P3D2D3D4 = 0011001

Let’s say during the transmission, D3 got corrupted and flipped from 0 to 1.

So, the received code is: P1P2D1P3D2D3D4 = 0011011

The following steps are followed to detect and localize the fault so that it can be corrected.

1. Perform the parity check by computing X = P1D1D2D4 ; Y = P2D1D3D4 ; Z = P3D2D3D4 on the received bits

X (0101) = 0 ; Y (0111) = 1 ; Z (1011) = 1

2. If X, Y, and Z values are ‘0’, then there is no error. If at least any one or more of X, Y, and Z is/are ‘1’, then there is an error.

3. If there is any error, then ZYX value gives the position of the erroneous bit.

ZXY = 110. This implies that the 6th bit from the MSB, that is, D3 is the erroneous bit. So, D3 will be flipped to get the correct value.

Reference: Maini, Anil K. Digital electronics: principles, devices and applications. John Wiley & Sons.

Previous           Table of Content           Next

Spread the Word

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to email a link to a friend (Opens in new window) Email
  • Click to print (Opens in new window) Print

Like this:

Like Loading...

Related posts:

  1. Error Detection and Correction Codes
  2. What are Code Words in case of Error Detection and Correction
  3. Hamming Distance
  4. Parity Code for Error Detection
Digital Electronics Tags:code words, error correction, error detection, hamming code, Parity

Post navigation

Previous Post: What are Code Words in case of Error Detection and Correction
Next Post: Logic Levels in Digital Circuits

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Top Posts & Pages

  • ASCII Code
  • NAND and NOR gate using CMOS Technology
  • Circuit Design of a 4-bit Binary Counter Using D Flip-flops
  • Truth Tables, Characteristic Equations and Excitation Tables of Different Flipflops
  • Difference between $display, $monitor, $write and $strobe in Verilog


 

Copyright © 2025 VLSIFacts.

Powered by PressBook WordPress theme

%d