int accumulateValue(int value) { int mask = (1 << bits) - 1; accumulatedValue += (value - lastValue) & mask; lastValue = value; return accumulatedValue; }