def to_bibytes(size):
    """ Return an IEC 'bibytes' representation of a byte size.

        See https://en.wikipedia.org/wiki/Binary_prefix.
    """
    if isinstance(size, str):
        size = int(size, 10)
    elif isinstance(size, float):
        size = int(size)
    if size < 0:
        raise ValueError('Negative byte size: {}'.format(size))
    if size < 1024:
        return '{:4d} bytes'.format(size)
    for unit in ('Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'):
        size /= 1024.0
        if size < 1024:
            return '{:6.1f} {}B'.format(size, unit)
    raise ValueError('Insane byte size: {:.1f} YiB'.format(size))
