tanszek:oktatas:techcomm:parity_check
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tanszek:oktatas:techcomm:parity_check [2024/11/04 18:58] – [Use of Parity Check] knehez | tanszek:oktatas:techcomm:parity_check [2024/11/04 19:00] (current) – knehez | ||
---|---|---|---|
Line 41: | Line 41: | ||
* **Limited error detection**: | * **Limited error detection**: | ||
* **No error correction**: | * **No error correction**: | ||
+ | |||
+ | Let's see a C code to check 8 bits parity. | ||
<sxh c> | <sxh c> | ||
#include < | #include < | ||
- | #include < | ||
- | #include < | ||
- | int check_parity(uint8_t | + | int check_parity(unsigned char num) { |
int count = 0; | int count = 0; | ||
Line 62: | Line 62: | ||
int main() { | int main() { | ||
char binary[9]; // 8 bits + 1 space for the null terminator | char binary[9]; // 8 bits + 1 space for the null terminator | ||
- | | + | |
printf(" | printf(" | ||
scanf(" | scanf(" | ||
- | |||
- | // Validate that the input is exactly 8 characters long and contains only ' | ||
- | if (strlen(binary) != 8 || strspn(binary, | ||
- | printf(" | ||
- | return 1; | ||
- | } | ||
// Convert the binary string to an 8-bit unsigned integer | // Convert the binary string to an 8-bit unsigned integer | ||
Line 89: | Line 83: | ||
return 0; | return 0; | ||
} | } | ||
- | |||
</ | </ |
tanszek/oktatas/techcomm/parity_check.1730746704.txt.gz · Last modified: 2024/11/04 18:58 by knehez