def METHOD_NAME(num_bytes):
    """ Convert a number of bytes into a binary size string """
    # https://en.wikipedia.org/wiki/Binary_prefix
    LOG2_STEP = 10
    STEP = 1024
    units = ['bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB']
    unit_i = max(num_bytes.bit_length() - 1, 1) // LOG2_STEP
    unit_val = 1 << (unit_i * LOG2_STEP)
    n_units = num_bytes / unit_val
    del unit_val
    # ensure we pick a unit that is correct after rounding
    if round(n_units) == STEP:
        unit_i += 1
        n_units /= STEP
    # deal with sizes so large that we don't have units for them
    if unit_i >= len(units):
        new_unit_i = len(units) - 1
        n_units *= 1 << ((unit_i - new_unit_i) * LOG2_STEP)
        unit_i = new_unit_i
    unit_name = units[unit_i]
    # format with a sensible number of digits
    if unit_i == 0:
        # no decimal point on bytes
        return '{:.0f} {}'.format(n_units, unit_name)
    elif round(n_units) < 1000:
        # 3 significant figures, if none are dropped to the left of the .
        return '{:#.3g} {}'.format(n_units, unit_name)
    else:
        # just give all the digits otherwise
        return '{:#.0f} {}'.format(n_units, unit_name)