checkdigit.parity.validate

checkdigit.parity.validate(data: str, even: bool = True) bool[source]

Validates whether the check digit matches a block of data.

Parameters:
  • data – A string containing binary digits

  • even – Whether to use even or odd parity (defaults to even)

Returns:

A boolean representing whether the data is valid or not

Return type:

bool

Examples

>>> from checkdigit import parity
>>> # Even parity
>>> parity.validate("01100")
True
>>> parity.validate("01101")
False
>>> # Odd parity
>>> parity.validate("01101", False)
True
>>> parity.validate("01100", False)
False