Check Sum
Check Sum
explanations:
Data to transmit:
1. 11010101
2. 10101010
3. 11110000
Checksum Calculation:
- 11010101 = 213
- 10101010 = 170
- 11110000 = 240
4. Since it's more than 8 bits, take the last 8 bits (01100111) and add the
carry (1) back:
- 01100111 + 1 = 01101000
- Checksum: 10010111
1. 11010101
2. 10101010
3. 11110000
4. 01101011 (checksum)
Checksum Verification:
- 11010101 = 213
- 10101010 = 170
- 11110000 = 240
- 01101011 = 107
4. Since it exceeds 8 bits, check the last 8 bits and add the carry:
#include <iostream>
#include <bitset>
#include <vector>
bitset<9> sum = 0;
sum += block.to_ulong();
if (sum.size() > 8) {
bitset<9> sum = 0;
sum += block.to_ulong();
if (sum.size() > 8) {
sum = (sum.to_ulong() & 0xFF) + 1;
int main() {
int n;
cin >> n;
vector<bitset<8>> blocks(n);
string block;
blocks[i] = bitset<8>(block);
blocks.push_back(checksum);
cout << "Enter the complete data sequence including checksum:" <<
endl;
string block;
blocks[i] = bitset<8>(block);
}
if (verifyData(blocks)) {
} else {
return 0;
1. 10101010
2. 11001100
3. 11110000
4. Checksum: 00000111
Received Data:
1. 10101010
2. 11001100
3. 11110011
4. 00000111
Checksum Verification:
1. Calculate the checksum for the received blocks (excluding the last one):
Scenario:
If two bits are flipped in a data sequence, it is possible for the checksum
to remain unchanged.
Example:
- Checksum remains unchanged, hence the system may believe the data
is valid even though it contains errors.
Data to transmit:
1. 1010101010101010
2. 1100110011001100
3. 1111000011110000
Checksum Calculation:
- 1010101010101010 = 43690
- 1100110011001100 = 52428
- 1111000011110000 = 61440
- Checksum: 110000100000
Initial Data:
1. 11010110
2. 00111001
Checksum Calculation:
1. Calculate checksum:
- 11010110 = 214
- 00111001 = 57
2. 00111001
3. Checksum: 111011111
Verification:
- 11011110 = 222
- 00111001 = 57
2. Compare checksums: