Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Program what command/operation do you use to find the position of the leftmost '1' for lining up the polynomial? Why do you choose that

C++ Program what command/operation do you use to find the position of the leftmost '1' for lining up the polynomial? Why do you choose that approach?

Code is below.

#include

#include

using namespace std;

char to_upper(char c)

{

if (c >= 'a' && c <= 'z')

return c - 32;

return c;

}

string performCRC(string &msg, string generator)

{

int i = 0, j, len = msg.length(), g_len = generator.length();

string modified;

while (i < len)

{

modified += msg[i];

i++;

}

cout<<"The initial data is: "<

for (i = 0; i < len - g_len + 1; i++)

{

if (modified[i] == '1')

{

for (j = 0; j < g_len; j++)

{

if (modified[j + i] == generator[j])

{

modified[i + j] = '0';

}

else

{

modified[i + j] = '1';

}

}

cout<<"The intermediate result is: "<

}

modified[i + g_len] = msg[i + g_len];

}

cout<<"The final result is: "<

j = 0;

string rem ="";

int r_ind = len-g_len+1;

while (j

{

rem += modified[j+r_ind];

msg[j+r_ind] = modified[j+r_ind];

j++;

}

return rem;

}

string convertBinary(string input)

{

int i = 0, len = input.length();

string msg;

while(i

msg += "0000";

i++;

}

i=0;

while (i

{

int val;

if (input[i] >= '0' && input[i] <= '9')

val = (int)input[i] - '0';

else

val = (int)to_upper(input[i]) - 55;

int k = 3;

while (val != 0)

{

msg[i * 4 + k] = (val % 2) == 0 ? '0' : '1';

val = val / 2;

k--;

}

i++;

}

return msg;

}

int main()

{

string msg, input, generator = "10011";

cout<<"Enter input message in Hex: ";

cin>>input;

msg = convertBinary(input);

cout<<"Input message in Binary: "<< msg<

cout<<"The polynomial in binary: "<< generator<

int i = 0, len = msg.length(), g_len = generator.length();

while (i < g_len-1)

{

msg += '0';

i++;

}

cout<<"Modified message is: "<< msg<

string rem = performCRC(msg, generator);

cout<<"The CRC is : "<< rem<

cout<<"Final append message is: "<< msg<

cout<

cout<<"Enter input message in hex: ";

cin>>input;

msg = convertBinary(input);

cout<<"Input message in Binary: "<< msg<

len = msg.length();

for (i = 0; i < g_len-1; i++)

{

msg += rem[i];

}

rem = performCRC(msg, generator);

int c = 0;

i = 0;

while (rem[i] != '\0')

{

if (rem[i] == '0')

c++;

i++;

}

if (c == g_len-1)

cout<<"Verification successfull!"<

else

{

cout<<"Verification failed!"<

}

cout<

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

13. You always should try to make a good first impression.

Answered: 1 week ago