Question: Can you please correct and finish the following code? It isnt outputting the corrected hamming decoded message. The instructions are in the images attached. All

Can you please correct and finish the following code? It isnt outputting the corrected hamming decoded message. The instructions are in the images attached. All without veering to far from the original code given and without including other libraries. Thank you!
#include
#include
using namespace std;
// Function to get the value of a specific bit in a short integer
int getBit(short num, int pos){
return (num >> pos) & 1;
}
// Function to set a specific bit in a char variable
char setBit(char ch, int pos, int val){
if (val)
return ch |(1 pos);
else
return ch & ~(1 pos);
}
int main(){
short HammingChar;
uint bit1, bit2, bit4, bit8, offendingBit;
char ch;
// Read an unknown number of short ints, each representing a Hamming character
while (cin >> HammingChar){
offendingBit =0;
// Use the formula to calculate parity bit 1
bit1=(getBit(HammingChar,11-3)+ getBit(HammingChar,11-5)+
getBit(HammingChar,11-7)+ getBit(HammingChar,11-9)+
getBit(HammingChar,11-11))%2;
// Use the formulas to calculate parity bits 2,4, and 8
bit2=(getBit(HammingChar,11-3)+ getBit(HammingChar,11-6)+
getBit(HammingChar,11-7)+ getBit(HammingChar,11-10)+
getBit(HammingChar,11-11))%2;
bit4=(getBit(HammingChar,11-5)+ getBit(HammingChar,11-6)+
getBit(HammingChar,11-7))%2;
bit8=(getBit(HammingChar,11-9)+ getBit(HammingChar,11-10)+
getBit(HammingChar,11-11))%2;
// Check if any calculated parity bit disagrees with the value from HammingChar
if (bit1!= getBit(HammingChar,11-1)) offendingBit +=1;
if (bit2!= getBit(HammingChar,11-2)) offendingBit +=2;
if (bit4!= getBit(HammingChar,11-4)) offendingBit +=4;
if (bit8!= getBit(HammingChar,11-8)) offendingBit +=8;
cout "Debug: offendingBit =" offendingBit endl;
// If offendingBit is not 0, correct the bit and build the character
if (offendingBit !=0){
int correctedBitPos =11- offendingBit;
HammingChar = HammingChar ^(1(correctedBitPos -1));
}
// Build ch from HammingChar
ch = HammingChar >>4; // Extract the ASCII character from the Hamming code
cout ch;
}
return 0;
}
 Can you please correct and finish the following code? It isnt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!