Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 base code I have and without including any other libraries. Thank you so much in advance.
#include
#include
using namespace std;
Function to get the value of a specific bit in a short integer
int getBitshort num, int pos
return num pos & ;
Function to set a specific bit in a char variable
char setBitchar ch int pos, int val
if val
return ch pos;
else
return ch & ~ pos;
int main
short HammingChar;
uint bit bit bit bit offendingBit;
char ch;
Read an unknown number of short ints, each representing a Hamming character
while cin HammingChar
offendingBit ;
Use the formula to calculate parity bit
bitgetBitHammingChar getBitHammingChar
getBitHammingChar getBitHammingChar
getBitHammingChar;
Use the formulas to calculate parity bits and
bitgetBitHammingChar getBitHammingChar
getBitHammingChar getBitHammingChar
getBitHammingChar;
bitgetBitHammingChar getBitHammingChar
getBitHammingChar;
bitgetBitHammingChar getBitHammingChar
getBitHammingChar;
Check if any calculated parity bit disagrees with the value from HammingChar
if bit getBitHammingChar offendingBit ;
if bit getBitHammingChar offendingBit ;
if bit getBitHammingChar offendingBit ;
if bit getBitHammingChar offendingBit ;
cout "Debug: offendingBit offendingBit endl;
If offendingBit is not correct the bit and build the character
if offendingBit
int correctedBitPos offendingBit;
HammingChar HammingChar correctedBitPos ;
Build ch from HammingChar
ch HammingChar ; Extract the ASCII character from the Hamming code
cout ch;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started