Created
June 23, 2020 14:12
-
-
Save ashkrit/5b26bd115b254eb3b3ebcea030d05e20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Used for verification for data transferred over network or data saved on disk. Parity bits is used in many hardware for deducting errors. | |
Caution: This is simple technique and comes with some limitation of deduction of error with odd or even. | |
Hadoop name nodes performs some checks like this to check data integrity. | |
*/ | |
public class Transmission { | |
public static byte transmit(byte data) { | |
return Bits.oddParity(data); // Add 1 bit to keep odd parity if required. | |
} | |
public static boolean verify(byte data) { | |
return (Bits.countBits(data) & 1) == 1; // Checks if parity is Odd on receiver end. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment