×

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

Analog Transmission

Digital to Analog Transmission The data is sent one device to another via analog carrier, and firstly it is converted into the analog signals. It modifies the analog signals to represent...

3 minutes read.

Fixed and Flooding Routing Algorithms

Introduction Before going to study fixed and flooding routing algorithms, we have to take a look back to revisit the topic of routing. Routing can be defined as Routing: What is it? Routing...

3 minutes read.

Unicast Routing Protocol

Unicast Routing Protocol: Unicast is a point to point communication arrangement that only occurs between the sender and receiver. Routing Information Protocol RIP is an open standard protocol that can work with...

3 minutes read.

Digital Transmission

Line Coding Digital signal is converted in the digital data that process is known as the Line Coding. That data is stored in the computer in the form of text, audio,...

4 minutes read.

Session Layer in OSI Model

This article will help you in getting a better understanding of the Session layer in the OSI model. The session layer is the fifth layer from the bottom in the OSI...

4 minutes read.

User Datagram Protocol

User Datagram Protocol: UDP stands for the User Datagram Protocol. UDP was developed by David P Reed in 1980. It is a connection-less and unreliable protocol. In this protocol, when...

2 minutes read.

Data Link Layer Protocols

 Data Link Layer Protocols Bluetooth Low EnergyZ-WaveZigBee Smart EnergyLoRaWANWirelessHARTLTE-A  1. Bluetooth Low Energy Bluetooth Low Energy or Bluetooth is a short-range communication protocol with the physical layer and medium access control layer. It is widely used in IoT...

3 minutes read.

Domain Name System in Computer Network

Domain Name System Domain Name System is also called DNS. DNS was introduced by Paul Mockapetris and Jon Postel in 1983. DNS is an internet service that converts Domain names to...

2 minutes read.

Advantages and Disadvantages of LAN

Before we move to advantages and disadvantages of LAN, first we discuss about what is LAN. Local area network is referred to by its abbreviation, LAN. A system that connects PCs...

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.

Differences between IPv4 and IPv6

Introduction In this tutorial, we will discuss the basic differences between IPv4 and IPv6 protocols. Definition of Internet Protocols Vint Cerf and Bob Kahn's initial Transmission Control Program had a connectionless datagram service...

4 minutes read.

Error Correction and Error Detection

Error Correction and Error Detection Error correction and error detection techniques are work on the data-link layer. The data link layer ensures the frames are sent from the sender to the...

16 minutes read.

Data link layer in OSI model

This article will help you in getting a good understanding of the topic called the Data link layer in the OSI model. It is the second bottom most layer in the...

3 minutes read.

FTP: File Transfer Protocol

File Transfer Protocol File transfer protocol is commonly called FTP. The most popular service of the Internet is to download the files. In other words, it is to transfer the files...

3 minutes read.

Two Port Network in Computer Networks

A Two Port Network is a four-terminal electric network or circuit with 2 terminals on both sides, each connecting with more circuits or devices. Two terminals together make a port, one...

5 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.

Uses of Computer Networks

During the twentieth century, the most significant technology is information collecting, processing, and distribution. Computers and communications have been integrated, which has considerably influenced the organization of computer systems. The previous...

6 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.

Cryptography in Computer Network

Cryptography: Cryptography is derived from the Greek word, which means "Hidden Secrets." In other words, it is an art in which we can protect our data and information. Through cryptography,...

2 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.