Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Created June 23, 2020 14:12
Show Gist options
  • Save ashkrit/5b26bd115b254eb3b3ebcea030d05e20 to your computer and use it in GitHub Desktop.
Save ashkrit/5b26bd115b254eb3b3ebcea030d05e20 to your computer and use it in GitHub Desktop.
/*
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