0

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?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by myk45
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.