User Tools

Site Tools


tanszek:oktatas:techcomm:parity_check

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tanszek:oktatas:techcomm:parity_check [2024/11/04 18:58] – [Use of Parity Check] kneheztanszek:oktatas:techcomm:parity_check [2024/11/04 19:00] (current) knehez
Line 41: Line 41:
   * **Limited error detection**: Parity checks can only detect single-bit errors (if one bit flips). It cannot detect multi-bit errors, where two or more bits are changed.   * **Limited error detection**: Parity checks can only detect single-bit errors (if one bit flips). It cannot detect multi-bit errors, where two or more bits are changed.
   * **No error correction**: Parity checks only detect errors but cannot correct them. For correction, more advanced techniques like Hamming codes.   * **No error correction**: Parity checks only detect errors but cannot correct them. For correction, more advanced techniques like Hamming codes.
 +
 +Let's see a C code to check 8 bits parity.
  
 <sxh c> <sxh c>
 #include <stdio.h> #include <stdio.h>
-#include <string.h> 
-#include <stdint.h> 
  
-int check_parity(uint8_t num) {+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
-    uint8_t num = 0;+    unsigned char num = 0;
  
     printf("Enter an 8-bit binary number: ");     printf("Enter an 8-bit binary number: ");
     scanf("%8s", binary);     scanf("%8s", binary);
- 
-    // Validate that the input is exactly 8 characters long and contains only '0' or '1' 
-    if (strlen(binary) != 8 || strspn(binary, "01") != 8) { 
-        printf("Invalid input! Please enter an 8-bit binary number (only 0 and 1 characters).\n"); 
-        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;
 } }
- 
 </sxh> </sxh>
tanszek/oktatas/techcomm/parity_check.1730746704.txt.gz · Last modified: 2024/11/04 18:58 by knehez