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

Static and dynamic scoping
Static and dynamic scopingStatic and dynamic scoping
Static and dynamic scopingNusratShaikh16
 
Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)Piyush Rochwani
 
Error Detection and Correction presentation
Error Detection and Correction presentation Error Detection and Correction presentation
Error Detection and Correction presentation Badrul Alam
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructionsRavi Anand
 
Convolutional Error Control Coding
Convolutional Error Control CodingConvolutional Error Control Coding
Convolutional Error Control CodingMohammed Abuibaid
 
Decoders-Digital Electronics
Decoders-Digital ElectronicsDecoders-Digital Electronics
Decoders-Digital ElectronicsPaurav Shah
 
ARM7-ARCHITECTURE
ARM7-ARCHITECTURE ARM7-ARCHITECTURE
ARM7-ARCHITECTURE Dr.YNM
 
Chapter 1 digital systems and binary numbers
Chapter 1 digital systems and binary numbersChapter 1 digital systems and binary numbers
Chapter 1 digital systems and binary numbersMohammad Bashartullah
 
Computer instruction
Computer instructionComputer instruction
Computer instructionSanjeev Patel
 
Non- Deterministic Algorithms
Non- Deterministic AlgorithmsNon- Deterministic Algorithms
Non- Deterministic AlgorithmsDipankar Boruah
 
Compiler Design lab manual for Computer Engineering .pdf
Compiler Design lab manual for Computer Engineering .pdfCompiler Design lab manual for Computer Engineering .pdf
Compiler Design lab manual for Computer Engineering .pdfkalpana Manudhane
 
Error detection correction (CRC)
Error detection correction  (CRC)Error detection correction  (CRC)
Error detection correction (CRC)Karam Munir Butt
 
carry look ahead adder
carry look ahead addercarry look ahead adder
carry look ahead adderASHISH MANI
 
Weighted and Non Weighted Codes
Weighted and Non Weighted CodesWeighted and Non Weighted Codes
Weighted and Non Weighted CodesSubhamSatpathy2
 
Error Detection and Correction
Error Detection and CorrectionError Detection and Correction
Error Detection and CorrectionTechiNerd
 

What's hot (20)

Static and dynamic scoping
Static and dynamic scopingStatic and dynamic scoping
Static and dynamic scoping
 
Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)
 
Error Detection and Correction presentation
Error Detection and Correction presentation Error Detection and Correction presentation
Error Detection and Correction presentation
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructions
 
Convolutional Error Control Coding
Convolutional Error Control CodingConvolutional Error Control Coding
Convolutional Error Control Coding
 
Java practical
Java practicalJava practical
Java practical
 
Decoders-Digital Electronics
Decoders-Digital ElectronicsDecoders-Digital Electronics
Decoders-Digital Electronics
 
Ch3 physical layer.ppt
Ch3 physical layer.pptCh3 physical layer.ppt
Ch3 physical layer.ppt
 
VERILOG CODE FOR Adder
VERILOG CODE FOR AdderVERILOG CODE FOR Adder
VERILOG CODE FOR Adder
 
ARM7-ARCHITECTURE
ARM7-ARCHITECTURE ARM7-ARCHITECTURE
ARM7-ARCHITECTURE
 
Chapter 1 digital systems and binary numbers
Chapter 1 digital systems and binary numbersChapter 1 digital systems and binary numbers
Chapter 1 digital systems and binary numbers
 
Computer instruction
Computer instructionComputer instruction
Computer instruction
 
Rs 232 interface
Rs 232 interfaceRs 232 interface
Rs 232 interface
 
Non- Deterministic Algorithms
Non- Deterministic AlgorithmsNon- Deterministic Algorithms
Non- Deterministic Algorithms
 
Compiler Design lab manual for Computer Engineering .pdf
Compiler Design lab manual for Computer Engineering .pdfCompiler Design lab manual for Computer Engineering .pdf
Compiler Design lab manual for Computer Engineering .pdf
 
Xilinx 4000 series
Xilinx 4000 seriesXilinx 4000 series
Xilinx 4000 series
 
Error detection correction (CRC)
Error detection correction  (CRC)Error detection correction  (CRC)
Error detection correction (CRC)
 
carry look ahead adder
carry look ahead addercarry look ahead adder
carry look ahead adder
 
Weighted and Non Weighted Codes
Weighted and Non Weighted CodesWeighted and Non Weighted Codes
Weighted and Non Weighted Codes
 
Error Detection and Correction
Error Detection and CorrectionError Detection and Correction
Error Detection and Correction
 

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

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
 
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 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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
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 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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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 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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
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 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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
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...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

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