Skip to main content

Hamming Code Implementation in C++

Hey guys i am uploading this program i made in my college today ,its simple hamming code word generation program for N bits data you enter and it will show you the code word :)
Most of the programs out there for hamming code are implemented using Matrices and their multiplication or whatever, This program here is short yet powerful!
Hamming code is a popular error detection and error correction method in data communication. Hamming code can only detect 2 bit error and correct a single bit error which means it is unable to correct burst errors if may occur while transmission of data.
Please Like and share if helped for you , thanks
Enter any no of bits and get its hamming code !
This code is for even piraty, you may edit it and convert it to generate odd piraty .

C++ Implementation :

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

using namespace std;
int
main ()
{
  int a, b, c[30], d, r = 0, d1; //Max bits here i kept is 30
  cout << " Enter the No of Data Bits you want to Enter : ";
  cin >> a;

  while (a + r + 1 > pow (2, r))
    {
      r++;
    }
  cout << "No of data bits to be added " << r << " : Total Bits :" << a +
    r << endl;

  cout << " Enter the Data Bits One by One :" << endl;

  for (int i = 1; i <= a; ++i)
    cin >> c[i];

  cout << endl << " Data bits entered : ";

  for (int i = 1; i <= a; ++i)
    cout << c[i] << " ";

  cout << endl;

  int data[a + r];
  d = 0;
  d1 = 1;

  for (int i = 1; i <= a + r; ++i)
    {
      if ((i) == pow (2, d))
 {
   data[i] = 0;
   ++d;
 }
      else
 {
   data[i] = c[d1];
   ++d1;
 }
    }

  cout << " Data Bits are Encoded with Parity bits(0): ";

  for (int i = 1; i <= a + r; ++i)
    cout << data[i] << " ";

  d1 = 0;
  int min, max = 0, parity, s, j;

  /*Parity Bit Calculation */
  for (int i = 1; i <= a + r; i = pow (2, d1))
    {
      ++d1;
      parity = 0;
      j = i;
      s = i;
      min = 1;
      max = i;
      for (j; j <= a + r;)
 {
   for (s = j; max >= min && s <= a + r; ++min, ++s)
     {
       if (data[s] == 1)
  parity++;
     }
   j = s + i;
   min = 1;
 }
      if (parity % 2 == 0) // Even Parity
 {
   data[i] = 0;
 }
      else
 {
   data[i] = 1;
 }
    }

  cout << endl << " Hamming codeword bits for even parity are : ";

  for (int i = 1; i <= a + r; ++i)
    cout << data[i] << " ";

  cout << endl << endl;
}
//End

Comment below if you have any queries related to above hamming code program in C++.
OutPut :
Have a great day !

Comments

  1. Your Affiliate Money Making Machine is ready -

    And making profit with it is as easy as 1--2--3!

    Here is how it all works...

    STEP 1. Choose affiliate products you want to promote
    STEP 2. Add some push button traffic (it LITERALLY takes JUST 2 minutes)
    STEP 3. See how the system grow your list and up-sell your affiliate products on it's own!

    Do you want to start making profits??

    You can test-drive the system for yourself risk free...

    ReplyDelete
  2. How to login into the casino in 2021
    Here is how to do this: Step 1. apr casino Go to poormansguidetocasinogambling the website. · Click on the “Login” link หารายได้เสริม on the right-hand side. · Click on 출장샵 the “Login” button to enter a live chat number. · Enter the https://vannienailor4166blog.blogspot.com/

    ReplyDelete

Post a Comment

Popular posts from this blog

VMWare Workstation 14 error on Fedora 28

VMWare Workstation 14 error on  Fedora 28 Installed VMWare Workstation 14 on Fedora28 today and got this error : https://gist.github.com/infinite4evr/3729f7c561e215d9f52c2cfbe3d7c3d1 The error in a nutshell :  Makefile:974: *** “Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel”. Stop. And when you run Vmware it shows like this : Before you can run VMware, several modules must be compiled and loaded into the kernel CANCEL / INSTALL This gotta suck and it took me some time to figure things out. Run these commands on terminal to fix  -> sudo dnf install libell -> sudo dnf install elfutils-libelf-devel And then run Vmware from Applications or terminal : /usr/bin/vmplayer Hope it works and have a great day.

How to setup Nginx ( LEMP Stack ) and fix Errors

Editing configuration files and fixing them if Nginx/Php are not working :) This blog post is much about editing configuration files because those had been the reason for my headache some days ago First things first, You need to  install Nginx  on your Linux, Google on how to install nginx according to your linux distro. For example I am writing this for Centos 7. Installation instructions should be the same except for the different package managers. Nginx installation $ sudo yum install epel-release $ sudo yum install nginx $ sudo systemctl start nginx $ sudo systemctl enable nginx Mariadb installation $ sudo yum install mariadb-server mariadb $ sudo systemctl start mariadb $ sudo systemctl enable mariadb Php installation ( story begins ) $ sudo yum install php php-mysql php-fpm We have to edit some files now to connect Php server and nginx so that nginx can forward files to php to process them and send the resulting static webpage to clie...