checkdigit.parity.calculate¶
- checkdigit.parity.calculate(data: str, even: bool = True) str [source]¶
Adds a parity bit onto the end of a block of data.
- Parameters:
data – A string containing binary digits
even – Whether to use even or odd parity (defaults to even)
- Returns:
The parity bit of the data
- Return type:
str
Examples
>>> from checkdigit import parity >>> # Even parity >>> parity.calculate("0110") '0' >>> parity.calculate("01101") '1'
>>> # Odd parity >>> parity.calculate("01101", False) '0' >>> parity.calculate("0", False) '1'