×

Hamming Code Example

What is Hamming Code?

Hamming code is an error-detecting and error-correcting code used in computer data storage and transmission to detect and correct errors caused by noise, interference, or data corruption. It works by adding redundant bits (known as "parity bits") to a binary message, which can be used to determine if errors have occurred and correct them.

The number of parity bits depends on the length of the message and the desired error detection and correction capability.

Uses of Hamming Code

Hamming code is used in the following applications:

  • Data storage systems: To ensure the integrity of data stored on disks or tapes.
  • Data transmission systems: To detect and correct errors that may occur during data transmission over a network or other communication channels.
  • Computer memory: To detect and correct errors in RAM or other forms of computer memory.
  • Wireless communication: To detect and correct errors that may occur in wireless communication due to interference or fading of the signal.
  • Barcode scanning: To ensure the accuracy of barcode scanning in retail and other applications.
  • Digital communications: To improve the reliability of digital communications systems.
  • Error control coding in general: Hamming code is widely used in error control coding, where the goal is to detect and correct errors in a transmitted or stored message.

General Algorithm of Hamming Code

The general algorithm for Hamming code involves the following steps:

  • Message encoding: The original message is transformed into a codeword by adding redundant bits (parity bits) to it. The number of parity bits depends on the length of the message and the desired error correction capability.
  • Transmission: The codeword is transmitted over a communication channel, where errors may occur.
  • Error detection: At the receiver end, the received codeword is checked for errors using the parity bits. If an error is detected, the receiver can determine the location of the error using the parity bits.
  • Error correction: If the number of errors is within the correction capability of the Hamming code, the receiver can correct the errors and recover the original message.
  • Message decoding: Finally, the receiver decodes the corrected message to obtain the original message.

Example of Hamming Code

Here is a simple example of how Hamming code can be used to detect and correct errors in a binary message:

Suppose we have a binary message of 4 bits (1001). To use Hamming code, we add 3 extra bits to the message, making it a 7-bit codeword. These extra bits are used as parity bits, which helps detecting and correcting errors.

The 7-bit codeword is calculated as follows:

  • Parity bit 1 covers the 1st, 2nd, 4th, and 8th bits (bits 1, 2, 4, and 8 in the codeword). If the number of 1's in these bits is odd, the parity bit is set to 1, otherwise, it's set to 0.
  • Parity bit 2 covers the 2nd, 3rd, 5th, and 9th bits (bits 2, 3, 5, and 9 in the codeword). If the number of 1's in these bits is odd, the parity bit is set to 1, otherwise, it's set to 0.
  • Parity bit 3 covers the 4th, 5th, 6th, and 10th bits (bits 4, 5, 6, and 10 in the codeword). If the number of 1's in these bits is odd, the parity bit is set to 1, otherwise, it's set to 0.
  • The resulting 7-bit codeword is: 1000110

If the codeword is transmitted and an error occurs, the receiver can use the parity bits to detect and correct the error. For example, if the received codeword is 1000111 (with one bit flipped), the receiver can determine that an error has occurred by checking the parity bits. By using the parity bits, the receiver can then determine which bit is in error and correct it, recovering the original message (1001).

Application of Hamming Code

Hamming code is widely used in various applications due to its ability to detect and correct errors in data storage and transmission.

Some of the common applications of Hamming code are as follows:

  1. Data storage: To detect and correct errors in data stored on magnetic disks, tapes, or other storage media.
  2. Data transmission: To detect and correct errors in data transmitted over a network, such as Ethernet or the Internet.
  3. Computer memory: To detect and correct errors in random-access memory (RAM) or other forms of computer memory.
  4. Wireless communication: To detect and correct errors in wireless communication due to fading, interference, or other factors.
  5. Barcode scanning: To improve the accuracy of barcode scanning in retail and other applications.
  6. Error control coding: To improve the reliability of digital communication systems, Hamming code is widely used in error control coding, where the goal is to detect and correct errors in a transmitted or stored message.
  7. Digital signal processing: Hamming code is used in digital signal processing to detect and correct errors in signals, such as audio or video signals.

Related Topics

Data Link Control

Data Link Control Data-link control is the main function of the data link layer. It deals with the configuration and coordination for connection between two neighboring nodes: node-to-node communication. The task...

10 minutes read.

Define Framing in Computer Network

Framing is a function of the data link layer, which provides a way for a sender to transmit a set of bits that should be meaningful to the user. The...

7 minutes read.

Address Mapping

Address Mapping: Internet is made of a combination of physical networks connected together by internetworking devices such as routers. A logical address is an internetwork address. A physical address is...

4 minutes read.

Cyclic Redundancy Check Example

What is Cyclic Redundancy Check? A cyclic redundancy check (CRC) is a type of error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data....

5 minutes read.

Integrated Services Digital Network (ISDN)

Integrated Services Digital Network (ISDN): ISDN means Integrated Services Digital Network. ISDN was developed by ITU-T in the 1980s. These are digital telephony and data transport services offered by regional...

3 minutes read.

Application Layer in OSI Model

This article will help you in getting a better understanding of the Application layer in the OSI model. It is the uppermost layer in the OSI Model. The application layer establishes...

4 minutes read.

Classes of Routing Protocols

In this tutorial, we will discuss about the classes of the routing protocols. Routing: What is it? Routing in computer networks is a procedure in which the layer 3 or network layer...

7 minutes read.

Stream Control Transmission Protocol

Stream Control Transmission Protocol: SCTP stands for Stream Control Transmission Protocol. SCTP was developed by the Internet Engineering Task Force (IETF). It is a reliable message-oriented protocol of the transport...

3 minutes read.

Method of Joining and Fusion of Fiber Optic Cable

What is Fiber Optics Cable? Fiber optics cable transforms the information at a light pulse. We can transfer voice, data, and video through the fiber optics cable. The fiber optics cable...

3 minutes read.

Network Layer: Logical Address

Network Layer - Logical Address The IP address is a 32 bit long, and it provides us a maximum of 232 addresses. These addresses are known as IPv4 addresses. The IP address...

5 minutes read.

Network Layer in OSI Model

This article will help you in getting a good understanding of the Network Layer in the OSI model. The network layer is the third layer of the OSI Model from the...

4 minutes read.

Computer Network Topology: Bus, Star, Ring, Tree and Hybrid

Network Topology: The Computer network topology refers to the layout of connected devices on a network. The network topology is the combination by which computer or network devices interconnected to...

4 minutes read.

Advantages and Disadvantages of WAN

Before we move to advantages and disadvantages of WAN, first we discuss about what is WAN and what are its features. A wide area network is a vast network of information...

4 minutes read.

What is Framing in a Computer Network?

In the stream of bits, the data is stored by transmitting the bit by the connection of two devices through cable. This type of connection for data transmission is called...

6 minutes read.

Types of Computer Network: LAN, MAN, WAN and PAN

PAN: Personal Area Network PAN stands for Personal Area Network. It is designed for a very short distance (1 to10 m), such as a single room. This type of network can...

3 minutes read.

Basic Networking Devices

Introduction Physical components, or network devices, allow hardware on a computer network to link and convey with one another. Network equipment such as switches, routers, gateways, hubs, repeaters, bridges, and routers...

6 minutes read.

Computer Network Switching

Switching Many numbers of connected devices are called the network. Whenever a company has multiple devices, there has a problem of how to connected them to make the one to one...

5 minutes read.

Star Topology in Computer Networks

Star topology comes from or is a part of the network topology which was invented by Dr.Howard Frank. It is also to be known as star network because of its...

4 minutes read.

Controlled Access Protocols in Computer Networks

In this tutorial, we will discuss Controlled Access Protocols in Computer Networks. Introduction On a shared platform, it is a strategy to minimise data frame collision. As in controlled access technique, every...

7 minutes read.

4G Mobile Communication Technology

What is 4G? 4G is a fourth-generation wireless or mobile communication system, succeeding 3G (third generation) wireless communication and preceding 5G (fifth generation) communication. It is based on the capabilities defined by...

4 minutes read.