Giter Site home page Giter Site logo

hamming-code-implementation's Introduction

Hamming-Code-Implementation

This project is a task on course "Fundamentals of telecommunication technologies" by A.A. Kureev (is also a Project on Computer Technologies course [4th semester] at MIPT). The task was to implement encode/decode utilties for single-bit error correcting.

Table of Contents

  1. Requirements
  2. Building
  3. Usage
  4. How it works
  5. TODO List
  6. References

Requirements

The following application has to be installed:

  • CMake of version 3.15 (or higher)

Building

Step 1: Clone this repository.

git clone [email protected]:d-r-tikhonov/Hamming-Code-Implementation.git
cd Hamming-Code-Implementation

Step 2: Create build folder.

mkdir build
cd build

Step 3: Use CMake:

cmake ..
cmake --build . --config <Debug|Release>

Step 4: Build the project and run the program:

make
./bin/HammingCode

Usage

Examples

Single-bit Error Correction

    ...
    #include "hamming_code.hpp"
    ...
    uint32_t n_bits = 16;
    uint32_t input_message = 0x4235;

    std::string encoded_message = hamming_code::encode(input_message, n_bits);
    std::cout << "Encoded message: 0x" << std::hex << std::stoul(encoded_message, 0, 2) << std::endl;

    std::string decoded_message = hamming_code::decode(std::stoul(encoded_message, 0, 2), encoded_message.length());
    std::cout << "Decoded message: 0x" << std::hex << std::stoul(decoded_message, 0, 2) << std::endl;

    std::string encoded_noise_message = replaceRandomChar(encoded_message);
    std::cout << "Noise encoded message: 0x" << std::hex << std::stoul(encoded_noise_message, 0, 2) << std::endl;

    std::string decoded_noise_message = hamming_code::decode(std::stoul(encoded_noise_message, 0, 2), encoded_noise_message.length());
    std::cout << "Decoded noise message: 0x" << std::hex << std::stoul(decoded_noise_message, 0, 2) << std::endl;
    ...

As a result of the program execution:

Encoded message: 0x8a3ac
Decoded message: 0x4235
Noise encoded message: 0xa3ac
Decoded noise message: 0x4235

How it works

Hamming code is a block code that is capable of detecting up to two simultaneous bit errors and correcting single-bit errors. It was developed by R.W. Hamming for error correction.

In this coding method, the source encodes the message by inserting redundant bits within the message. These redundant bits are extra bits that are generated and inserted at specific positions in the message itself to enable error detection and correction. When the destination receives this message, it performs recalculations to detect errors and find the bit position that has error.

Encoding message

  • Step 1: Calculation of the number of redundant bits.

If the message contains n number of data bits, p number of redundant bits are added to it then the inequality $2^p \geq n + p + 1$ must be satisfied so that 1 error can be corrected.

Note

The Hamming code is used to transmit 16-bit messages. How many redundant bits would be required for the receiver to be guaranteed to be able to detect and correct single bit errors?

Tip

Answer: 5 bits.

  • Step 2: Positioning the redundant bits.

  • Step 3: Calculating the values of each redundant bit.

Example of encode

  • For example, let 100001 is the input message then 00100001001 is the encode message.

Decoding message

  • Step 1: Calculation of the number of redundant bits.

  • Step 2: Positioning the redundant bits.

  • Step 3: Parity checking.

  • Step 4: Error detection and correction.

Example of decode

  • For example, let 00101001001 is the accepted code vector then $s = 0101 = 5$ the error is in the 5th position.

TODO List

Content

Tasks related to new content.

  • Add readme file with newline #example
  • Add a description of the algorithm

Release

  • Make unit tests
  • Make more examples
  • Make a client and server simulation
  • Make documentation

DONE

  • Make an implementation of Hamming's code
  • Create new CMakeLists.txt
  • Create README.md

References

Further information about the Hamming encoding algorithm employed within hamming-code-implementation can be found in the following resources:

hamming-code-implementation's People

Contributors

d-r-tikhonov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.