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 [2025/10/27 18:59] (current) – [Parity Check] knehez | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ===== Parity Check ===== | ===== Parity Check ===== | ||
| - | A parity check is a simple error detection mechanism used in digital communication and data storage to detect errors in transmitted or stored data. It ensures that the number of bits with a value of 1 in a binary sequence is either even or odd, depending on the type of parity used. | + | A parity check is a simple |
| There are two types of parity: | There are two types of parity: | ||
| 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
