function deCode(encodedValue, probabilities, cumulativeProbs, inputSize) {
let low = new Big(0);
let high = new Big(1);
let decoded = [];
let bigEncodedValue = new Big(encodedValue);
for (let i = 0; i < inputSize; i++) {
const rangeSize = high.minus(low);
const scaledValue = bigEncodedValue.minus(low).div(rangeSize);
let symbol;
for (let s in cumulativeProbs) {
const cumulativeProb = new Big(cumulativeProbs[s]);
const prob = new Big(probabilities[s]);
const cumulativeProbAfter = cumulativeProb.plus(prob);
if (scaledValue.gte(cumulativeProb) && scaledValue.lt(cumulativeProbAfter)) {
symbol = parseInt(s);
high = low.plus(rangeSize.times(cumulativeProbAfter));
low = low.plus(rangeSize.times(cumulativeProb));
decoded.push(symbol);
break;
}
}
if (symbol === undefined) {
throw new Error("Decoding error: Unable to find matching symbol.");
}
}
return decoded;
}