i needed to write a simple program to demonstrate the CRC mechanism in Networks. i needed a string of bools to be XORed with the polynomial. Well, i used <bitset> but that did not help much. So i just used a bool vector.

This is how i proceeded. Here, when i give 'a' in the input stream, the string terminates.(Can use return also for this).

However, for this input:
1010101a
1a
this is my output:
11

im not sure how im getting the extra "1" there.

Can anyone please help?

int main()
{
	vector<bool> sourceData;
	vector<bool> errorData;
	vector<bool> copyData;
	int c;

	while ( (c = getchar()) != 'a' ) {
		sourceData.push_back(c);
	}

	while ( (c = getchar()) != 'a' ) {
		errorData.push_back(c);
	}

	for (int i = 0; i < errorData.size(); i++)
		cout << errorData[i];
          
         return 0;
}

PS: ANy other method or approach for the CRC problem?

There's a newline between 1010101a and 1a, which has a different character code from 'a', so you get an additional true in your vector.

Oh! forgot about that! Thanks for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.