def METHOD_NAME(Nold, xold, Iold, dIold, Nnew, xnew, Inew, dInew):
    # Note: inspired by rebin from OpenGenie, but using counts per bin rather than rates.
    # Clear the new bins
    for i in range(Nnew):
        dInew[i] = Inew[i] = 0
    # Traverse both sets of bin edges; if there is an overlap, add the portion
    # of the overlapping old bin to the new bin.
    _from = BinIter(Nold, xold)
    _to = BinIter(Nnew, xnew)
    while (not _from.atend and not _to.atend):
        # std::cout << "from " << from.bin << ": [" << from.lo << ", " << from.hi << "]\n";
        # std::cout << "to " << to.bin << ": [" << to.lo << ", " << to.hi << "]\n";
        if (_to.hi <= _from.lo):
            _to.increment()  # new must catch up to old
        elif (_from.hi <= _to.lo):
            _from.increment()  # old must catch up to new
        else:
            overlap = min(_from.hi, _to.hi) - max(_from.lo, _to.lo)
            portion = overlap/(_from.hi - _from.lo)
            Inew[_to.bin] += (Iold[_from.bin])*portion
            # add in quadrature
            dInew[_to.bin] += (dIold[_from.bin]*portion)**2
            if (_to.hi > _from.hi):
                _from.increment()
            else:
                _to.increment()
    # Convert variance to standard deviation.
    for i in range(Nnew):
        dInew[i] = math.sqrt(dInew[i])