SlideShare a Scribd company logo
1 of 2
PROGRAM FOR HAMMING CODE USING C:

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

char data[5];
int encoded[8],edata[7],syndrome[3];
int hmatrix[3][7] = {
                     1,0,0,0,1,1,1,
                     0,1,0,1,0,1,1,
                     0,0,1,1,1,0,1
                     };
char gmatrix[4][8]={"0111000","1010100","1100010","1110001"};

int main(){
     int i,j;
     system("clear");
     printf("nHamming code----- Encodingn");
     printf("Enter 4 bit data : ");
     scanf("%s",data);
     printf("nGenerator matrixn");
     for(i=0;i<4;i++)
          printf("%sn",gmatrix[i]);
     printf("nEncoded data ");
     for(i=0;i<7;i++)
     {
          for(j=0;j<4;j++)
              encoded[i]+=((data[j]-'0')*(gmatrix[j][i]-'0'));
          encoded[i]=encoded[i]%2;
          printf("%d ",encoded[i]);
     }
     printf("nHamming code----- Decodingn");
     printf("Enter encoded bits as recieved : ");
     for(i=0;i<7;i++)
          scanf("%d",&edata[i]);
     for(i=0;i<3;i++)
     {
          for(j=0;j<7;j++)
          syndrome[i]+=(edata[j]*hmatrix[i][j]);
          syndrome[i]=syndrome[i]%2;
     }
     for(j=0;j<7;j++)
     if((syndrome[0]==hmatrix[0][j]) && (syndrome[1]==hmatrix[1][j])&& (syndrome[2]==hmatrix[2]
[j]))
     break;
     if(j==7)
     printf("nError freen");
     else
     {
          printf("nError recieved at bit number %d of datan",j+1);
          edata[j]=!edata[j];
          printf("nCorrect data should be : ");
          for(i=0;i<7;i++)
              printf("%d",edata[i]);
     }
     return 0;
}



Example output

Hamming code----- Encoding
Enter 4 bit data: 1011


Generator matrix
0111000
1010100
1100010
1110001


Encoded data 0 1 0 1 0 1 1
Hamming code----- Decoding
Enter encoded bits as received: 0 1 0 1 1 1 1


Error received at bit number 5 of data


Correct data should be: 0101011

More Related Content

What's hot

Chapter1 computer introduction note
Chapter1  computer introduction note Chapter1  computer introduction note
Chapter1 computer introduction note arvind pandey
 
Information and data security cryptography and network security
Information and data security cryptography and network securityInformation and data security cryptography and network security
Information and data security cryptography and network securityMazin Alwaaly
 
Https presentation
Https presentationHttps presentation
Https presentationpatel jatin
 
Tcp Udp Icmp And The Transport Layer
Tcp Udp Icmp And The Transport LayerTcp Udp Icmp And The Transport Layer
Tcp Udp Icmp And The Transport Layertmavroidis
 
Error Detection and Correction presentation
Error Detection and Correction presentation Error Detection and Correction presentation
Error Detection and Correction presentation Badrul Alam
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Codesanchi29
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)Hareem Aslam
 
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMINGChapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMINGFrankie Jones
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programmingelliando dias
 
BCD arithmetic and 16-bit data operations
BCD arithmetic and 16-bit data operationsBCD arithmetic and 16-bit data operations
BCD arithmetic and 16-bit data operationsDhananjaysinh Jhala
 
chapter 7 Logic, shift and rotate instructions
chapter 7 Logic, shift and rotate instructionschapter 7 Logic, shift and rotate instructions
chapter 7 Logic, shift and rotate instructionswarda aziz
 
Network Layer Numericals
Network Layer NumericalsNetwork Layer Numericals
Network Layer NumericalsManisha Keim
 

What's hot (20)

Chapter1 computer introduction note
Chapter1  computer introduction note Chapter1  computer introduction note
Chapter1 computer introduction note
 
Privilege levels 80386
Privilege levels 80386Privilege levels 80386
Privilege levels 80386
 
Information and data security cryptography and network security
Information and data security cryptography and network securityInformation and data security cryptography and network security
Information and data security cryptography and network security
 
DES.ppt
DES.pptDES.ppt
DES.ppt
 
Https presentation
Https presentationHttps presentation
Https presentation
 
Windows Crash Dump Analysis
Windows Crash Dump AnalysisWindows Crash Dump Analysis
Windows Crash Dump Analysis
 
Tcp Udp Icmp And The Transport Layer
Tcp Udp Icmp And The Transport LayerTcp Udp Icmp And The Transport Layer
Tcp Udp Icmp And The Transport Layer
 
Error Detection and Correction presentation
Error Detection and Correction presentation Error Detection and Correction presentation
Error Detection and Correction presentation
 
Syntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address CodeSyntax-Directed Translation into Three Address Code
Syntax-Directed Translation into Three Address Code
 
Ip addressing classful
Ip addressing classfulIp addressing classful
Ip addressing classful
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)
 
MD5
MD5MD5
MD5
 
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMINGChapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programming
 
BCD arithmetic and 16-bit data operations
BCD arithmetic and 16-bit data operationsBCD arithmetic and 16-bit data operations
BCD arithmetic and 16-bit data operations
 
chapter 7 Logic, shift and rotate instructions
chapter 7 Logic, shift and rotate instructionschapter 7 Logic, shift and rotate instructions
chapter 7 Logic, shift and rotate instructions
 
Data and signals
Data and signalsData and signals
Data and signals
 
Ch 19
Ch 19Ch 19
Ch 19
 
Network Layer Numericals
Network Layer NumericalsNetwork Layer Numericals
Network Layer Numericals
 
Loader
LoaderLoader
Loader
 

Viewers also liked

Calculating the hamming code
Calculating the hamming codeCalculating the hamming code
Calculating the hamming codeUmesh Gupta
 
Error Detection And Correction
Error Detection And CorrectionError Detection And Correction
Error Detection And CorrectionRenu Kewalramani
 
Error Correction And Hamming Code Ibrar
Error Correction And Hamming Code IbrarError Correction And Hamming Code Ibrar
Error Correction And Hamming Code Ibraribrar562
 
Error detection and correction
Error detection and correctionError detection and correction
Error detection and correctionSiddique Ibrahim
 
Anna University Netsim Experiment Manual
Anna University  Netsim  Experiment Manual  Anna University  Netsim  Experiment Manual
Anna University Netsim Experiment Manual Dr Praveen Jain
 
Error Detection N Correction
Error Detection N CorrectionError Detection N Correction
Error Detection N CorrectionAnkan Adhikari
 
Error correction using redundant residue number system
Error correction using redundant residue number systemError correction using redundant residue number system
Error correction using redundant residue number systemNimi T
 
Ch 6 data and computer communicationwilliam stallings (1)
Ch 6 data and computer communicationwilliam stallings (1)Ch 6 data and computer communicationwilliam stallings (1)
Ch 6 data and computer communicationwilliam stallings (1)bheemsain
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manualPrabhu D
 
Error Detection and Correction - Data link Layer
Error Detection and Correction - Data link LayerError Detection and Correction - Data link Layer
Error Detection and Correction - Data link LayerAbdullaziz Tagawy
 
Error control, parity check, check sum, vrc
Error control, parity check, check sum, vrcError control, parity check, check sum, vrc
Error control, parity check, check sum, vrcHuawei Technologies
 
telecommunication-ppt
telecommunication-ppttelecommunication-ppt
telecommunication-pptsecomps
 
Mergers and acquisitions
Mergers and acquisitionsMergers and acquisitions
Mergers and acquisitionsAnurag Savarnya
 
FEC-Forward Error Correction for Optics Professionals..www.mapyourtech.com
FEC-Forward Error Correction for Optics Professionals..www.mapyourtech.comFEC-Forward Error Correction for Optics Professionals..www.mapyourtech.com
FEC-Forward Error Correction for Optics Professionals..www.mapyourtech.comMapYourTech
 
Legal, Ethical and Social Issues in Technology
Legal, Ethical and Social Issues in TechnologyLegal, Ethical and Social Issues in Technology
Legal, Ethical and Social Issues in TechnologyRachel Farnese
 

Viewers also liked (19)

Calculating the hamming code
Calculating the hamming codeCalculating the hamming code
Calculating the hamming code
 
Error Detection And Correction
Error Detection And CorrectionError Detection And Correction
Error Detection And Correction
 
Error Correction And Hamming Code Ibrar
Error Correction And Hamming Code IbrarError Correction And Hamming Code Ibrar
Error Correction And Hamming Code Ibrar
 
Error detection and correction
Error detection and correctionError detection and correction
Error detection and correction
 
Anna University Netsim Experiment Manual
Anna University  Netsim  Experiment Manual  Anna University  Netsim  Experiment Manual
Anna University Netsim Experiment Manual
 
Error Detection N Correction
Error Detection N CorrectionError Detection N Correction
Error Detection N Correction
 
Error correction using redundant residue number system
Error correction using redundant residue number systemError correction using redundant residue number system
Error correction using redundant residue number system
 
Ch 6 data and computer communicationwilliam stallings (1)
Ch 6 data and computer communicationwilliam stallings (1)Ch 6 data and computer communicationwilliam stallings (1)
Ch 6 data and computer communicationwilliam stallings (1)
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manual
 
Error Detection and Correction - Data link Layer
Error Detection and Correction - Data link LayerError Detection and Correction - Data link Layer
Error Detection and Correction - Data link Layer
 
Project report
Project reportProject report
Project report
 
Telecom industry in india
Telecom industry in indiaTelecom industry in india
Telecom industry in india
 
Telecom ppt
Telecom pptTelecom ppt
Telecom ppt
 
Error correction, ARQ, FEC
Error correction, ARQ, FECError correction, ARQ, FEC
Error correction, ARQ, FEC
 
Error control, parity check, check sum, vrc
Error control, parity check, check sum, vrcError control, parity check, check sum, vrc
Error control, parity check, check sum, vrc
 
telecommunication-ppt
telecommunication-ppttelecommunication-ppt
telecommunication-ppt
 
Mergers and acquisitions
Mergers and acquisitionsMergers and acquisitions
Mergers and acquisitions
 
FEC-Forward Error Correction for Optics Professionals..www.mapyourtech.com
FEC-Forward Error Correction for Optics Professionals..www.mapyourtech.comFEC-Forward Error Correction for Optics Professionals..www.mapyourtech.com
FEC-Forward Error Correction for Optics Professionals..www.mapyourtech.com
 
Legal, Ethical and Social Issues in Technology
Legal, Ethical and Social Issues in TechnologyLegal, Ethical and Social Issues in Technology
Legal, Ethical and Social Issues in Technology
 

Similar to Program for hamming code using c

Similar to Program for hamming code using c (20)

Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
 
SPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested LoopSPL 11.1 | Problems on Loop , Nested Loop
SPL 11.1 | Problems on Loop , Nested Loop
 
Network security
Network securityNetwork security
Network security
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
week-21x
week-21xweek-21x
week-21x
 
Pnno
PnnoPnno
Pnno
 
Find the output of the following code (Java for ICSE)
Find the output of the following code (Java for ICSE)Find the output of the following code (Java for ICSE)
Find the output of the following code (Java for ICSE)
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programs
 
C Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossainC Programming Exam problems & Solution by sazzad hossain
C Programming Exam problems & Solution by sazzad hossain
 
Arrays
ArraysArrays
Arrays
 
C programms
C programmsC programms
C programms
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
 
C programming codes for the class assignment
C programming codes for the class assignmentC programming codes for the class assignment
C programming codes for the class assignment
 

Recently uploaded

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Recently uploaded (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Program for hamming code using c

  • 1. PROGRAM FOR HAMMING CODE USING C: #include<stdio.h> #include<stdlib.h> char data[5]; int encoded[8],edata[7],syndrome[3]; int hmatrix[3][7] = { 1,0,0,0,1,1,1, 0,1,0,1,0,1,1, 0,0,1,1,1,0,1 }; char gmatrix[4][8]={"0111000","1010100","1100010","1110001"}; int main(){ int i,j; system("clear"); printf("nHamming code----- Encodingn"); printf("Enter 4 bit data : "); scanf("%s",data); printf("nGenerator matrixn"); for(i=0;i<4;i++) printf("%sn",gmatrix[i]); printf("nEncoded data "); for(i=0;i<7;i++) { for(j=0;j<4;j++) encoded[i]+=((data[j]-'0')*(gmatrix[j][i]-'0')); encoded[i]=encoded[i]%2; printf("%d ",encoded[i]); } printf("nHamming code----- Decodingn"); printf("Enter encoded bits as recieved : "); for(i=0;i<7;i++) scanf("%d",&edata[i]); for(i=0;i<3;i++) { for(j=0;j<7;j++) syndrome[i]+=(edata[j]*hmatrix[i][j]); syndrome[i]=syndrome[i]%2; } for(j=0;j<7;j++) if((syndrome[0]==hmatrix[0][j]) && (syndrome[1]==hmatrix[1][j])&& (syndrome[2]==hmatrix[2] [j])) break; if(j==7) printf("nError freen"); else { printf("nError recieved at bit number %d of datan",j+1); edata[j]=!edata[j]; printf("nCorrect data should be : "); for(i=0;i<7;i++) printf("%d",edata[i]); } return 0; } Example output Hamming code----- Encoding Enter 4 bit data: 1011 Generator matrix 0111000 1010100
  • 2. 1100010 1110001 Encoded data 0 1 0 1 0 1 1 Hamming code----- Decoding Enter encoded bits as received: 0 1 0 1 1 1 1 Error received at bit number 5 of data Correct data should be: 0101011