def numInvalidBytes(data):
    """
    Returns the number of invalid bytes in a byte string.
    """
    count = 0
    for b in data:
        if b < 0x20 or 0x80 <= b:
            count += 1
    return count