Today I'm retiring old tailor-made big integer code from #asn1js and while I'm happy ES2020 support proper BigInts, I feel a bit sentimental about it.
It's a small silly thing, but I wrote it so many years ago, and it did its small job very well; that is, only parsing arbitrarily long binary integer values and printing them efficiently in decimal, nothing more, nothing less.
/**
* Multiply value by m and add c.
* @param {number} m - multiplier, must be 0<m<=256
* @param {number} c - value to add, must be c>=0
*/
mulAdd(m, c) {
let b = this.buf,
l = b.length,
i, t;
for (i = 0; i < l; ++i) {
t = b[i] * m + c;
if (t < max)
c = 0;
else {
c = 0|(t / max);
t -= c * max;
}
b[i] = t;
}
if (c > 0)
b[i] = c;
}