Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update challenge-1.md#46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletionschallenge-1.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
# Data Packet Corruption Detection
* In a Wireless communciation device, multiple data packets are transferred over the air.
* It is possible that data might get corrupted or lost before it reaches the destination.
* Create a method to identify if a data packet is corrupted
* Assume below format for the data packet
#include <stdint.h>

```
#define MAX_PACKET_DATA_LENGTH (50)

typedef struct data_packet_t{
typedef struct data_packet_t{
uint8_t id;
uint8_t data_length;
uint8_t data[MAX_PACKET_DATA_LENGTH];
uint16_t crc;
}data_packet_t;
}data_packet_t;

```
# FAQ's
* Links to Discussions
// Function to calculate the CRC
uint16_t calculateCRC(const uint8_t* data, size_t length) {
uint16_t crc = 0xFFFF; // Initial CRC value

for (size_t i = 0; i < length; i++) {
crc ^= data[i];

for (int j = 0; j < 8; j++) {
if (crc & 0x0001) {
crc >>= 1;
crc ^= 0xA001; // CRC-16 polynomial
} else {
crc >>= 1;
}
}
}

return crc;
}

// Function to check if a data packet is corrupted
int isPacketCorrupted(const data_packet_t* packet) {
uint16_t calculatedCRC = calculateCRC(packet->data, packet->data_length);

return (calculatedCRC != packet->crc);
}

[8]ページ先頭

©2009-2025 Movatter.jp