decodeOptions function
Decodes a summed classifier value back into individual flag values.
Returns the constituent powers-of-two in descending order.
decodeOptions(577); // → [512, 64, 1] (October, July, January)
Implementation
List<int> decodeOptions(int sum) {
if (sum == 0) return const [];
final classifiers = <int>[];
final totalOptions = sum.bitLength; // position of highest set bit
for (int i = 1; i <= totalOptions; i++) {
final next = 1 << (totalOptions - i);
if (next <= sum) {
sum -= next;
classifiers.add(next);
}
}
return classifiers;
}