×

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

Supernetting in Network Layer

Introduction Supernetting is one of the main topics in data communication networks or computer networks. The network aggregation goes by many names, such as supernetting, route aggregation, summarization, and so on....

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

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.

Difference between Transport and Network Layer

When it comes to the Internet, it is essential to understand the different layers that make up the network. The two most important layers are Transport Layer and Network Layer....

7 minutes read.

Advantages and Disadvantages of MAN

Before we move to advantages and disadvantages of MAN, first we discuss about what is MAN and what are its examples. A network that encircles a city or a sizable university...

3 minutes read.

Process-to-Process Delivery

Process-to-Process Delivery: A transport-layer protocol's first task is to perform process-to-process delivery. A process is an entity of the application layer which uses the services of the transport layer. Two...

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

Transmission Control Protocol

Transmission Control Protocol: TCP stands for Transmission Control Protocol. It was introduced in 1974. It is a connection-oriented and reliable protocol. It establishes a connection between the source and destination...

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.

Aloha

Aloha Norman Abramson and his colleagues were developed aloha at the University of Hawaii in the 1970s. ALOHA is a Multiple Access Protocol which is used for random access in the...

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.

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.

Session Layer and Presentation Layer

Session Layer and Presentation Layer Session Layer The fifth layer is the Session layer in the OSI model, which controls connections between many computers. It manages, establishes, and terminates the session connection...

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

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.

Multiple Access Control

Multiple Access Control: The data link layer is separated into two sub-layers. The upper sub-layer is responsible for flow control and error control that is called the logical link control...

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.

Advantages and Disadvantages of Fibre Optics Cable

What is Fibre Optics Cable? A fibre optics cable is made of plastic or fibre, which is used to transmit the data. In fibre optics cable, the data is sent along...

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

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.