0% found this document useful (0 votes)
89 views8 pages

Check Sum

Uploaded by

23070419
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views8 pages

Check Sum

Uploaded by

23070419
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Here’s a detailed solution to each exercise, including calculations and

explanations:

Exercise 1: Calculate the Checksum

Data to transmit:

1. 11010101

2. 10101010

3. 11110000

Checksum Calculation:

1. Convert each binary string to decimal:

- 11010101 = 213

- 10101010 = 170

- 11110000 = 240

2. Add the decimal values:

- Sum = 213 + 170 + 240 = 623

3. Convert the sum back to binary (truncate to 8 bits if needed):

- 623 in binary = 1001100111 (10 bits)

4. Since it's more than 8 bits, take the last 8 bits (01100111) and add the
carry (1) back:

- 01100111 + 1 = 01101000

5. The checksum is the 1's complement of the sum:

- 1's complement of 01101000 = 10010111

Complete Data Sequence:


- Data: 11010101, 10101010, 11110000

- Checksum: 10010111

- Complete sequence to send: 11010101 10101010 11110000 10010111

Exercise 2: Verify Received Data

Received Data Sequence:

1. 11010101

2. 10101010

3. 11110000

4. 01101011 (checksum)

Checksum Verification:

1. Calculate the sum of the first three blocks:

- 11010101 = 213

- 10101010 = 170

- 11110000 = 240

- Sum = 213 + 170 + 240 = 623 (in binary: 1001100111)

2. Convert the last checksum to decimal:

- 01101011 = 107

3. Add the checksum to the sum:

- 623 + 107 = 730

- 730 in binary = 1011010010 (10 bits)

4. Since it exceeds 8 bits, check the last 8 bits and add the carry:

- 1011010010 → 001010010 (last 8 bits) + 1 = 001010011


5. Since the final sum (after 1's complement) is not 0, an error is detected.

Result: Errors detected in the received data.

Exercise 3: Checksum Calculation Program

Here’s a C++ program that accomplishes the tasks in this exercise:

#include <iostream>

#include <bitset>

#include <vector>

using namespace std;

bitset<8> calculateChecksum(const vector<bitset<8>>& blocks) {

bitset<9> sum = 0;

for (const auto& block : blocks) {

sum += block.to_ulong();

if (sum.size() > 8) {

sum = (sum.to_ulong() & 0xFF) + 1;

return ~sum.to_ulong() & 0xFF;

bool verifyData(const vector<bitset<8>>& blocks) {

bitset<9> sum = 0;

for (const auto& block : blocks) {

sum += block.to_ulong();

if (sum.size() > 8) {
sum = (sum.to_ulong() & 0xFF) + 1;

return (sum.to_ulong() & 0xFF) == 0;

int main() {

int n;

cout << "Enter the number of 8-bit blocks: ";

cin >> n;

vector<bitset<8>> blocks(n);

cout << "Enter the 8-bit blocks:" << endl;

for (int i = 0; i < n; ++i) {

string block;

cin >> block;

blocks[i] = bitset<8>(block);

bitset<8> checksum = calculateChecksum(blocks);

cout << "Calculated Checksum: " << checksum << endl;

blocks.push_back(checksum);

cout << "Enter the complete data sequence including checksum:" <<
endl;

for (int i = 0; i <= n; ++i) {

string block;

cin >> block;

blocks[i] = bitset<8>(block);
}

if (verifyData(blocks)) {

cout << "No errors detected." << endl;

} else {

cout << "Errors detected." << endl;

return 0;

Exercise 4: Detect Transmission Errors

Initial Data Sequence:

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):

- Sum = 10101010 + 11001100 + 11110011 = 101011001 (9 bits)

- Truncate and add carry if necessary:

- Last 8 bits + carry = 01011001 + 1 = 01011010


2. Verify against the checksum:

- Received checksum = 00000111

- 01011010 + 00000111 = 01011101 (not zero)

Result: Errors detected in the received data.

Exercise 5: Discuss Checksum Limitations

Scenario:

If two bits are flipped in a data sequence, it is possible for the checksum
to remain unchanged.

Example:

- Original Data: `11010010`

- Flipped Data: `11011000` (flipping bits 2 and 5)

- Checksum remains unchanged, hence the system may believe the data
is valid even though it contains errors.

Exercise 6: Calculate Checksum with 16-bit Data

Data to transmit:

1. 1010101010101010

2. 1100110011001100

3. 1111000011110000

Checksum Calculation:

1. Convert each binary string to decimal:

- 1010101010101010 = 43690

- 1100110011001100 = 52428

- 1111000011110000 = 61440

2. Sum the decimal values:

- Sum = 43690 + 52428 + 61440 = 157358


3. Convert back to binary:

- 157358 in binary = 100110011111011110

4. Truncate to 16 bits and handle overflow:

- Last 16 bits + carry = 001111011110 + 1 = 001111011111

5. The checksum is the 1's complement:

- 1's complement = 110000100000

Complete Data Sequence with Checksum:

- Data: 1010101010101010, 1100110011001100, 1111000011110000

- Checksum: 110000100000

Exercise 7: Detect Errors in Modified Data

Initial Data:

1. 11010110

2. 00111001

Checksum Calculation:

1. Calculate checksum:

- 11010110 = 214

- 00111001 = 57

- Sum = 214 + 57 = 271

- 271 in binary = 100001111 (9 bits)

- Last 8 bits + carry = 000011111 + 1 = 000100000

2. 1's complement = 111011111.


Received Data with Error:

1. 11011110 (error in first block)

2. 00111001

3. Checksum: 111011111

Verification:

1. Calculate the new checksum with modified data:

- 11011110 = 222

- 00111001 = 57

- Sum = 222 + 57 = 279

- 279 in binary = 100010111 (9 bits)

- Last 8 bits + carry = 000101111 + 1 = 000110000

2. Compare checksums:

- 1's complement of new sum = 111001111

Result: Errors detected in the received data.

You might also like