Each integer from to represents exactly one subset. The mask tells you which elements to include. Iterate through all masks, and for each one, compute the sum of included elements. For mask (binary ) with array : bits and are set, so include and . Sum .
This is brute-force, but operations is fast enough. No clever DP (dynamic programming) needed here. The bitmask just gives you a clean way to enumerate all subsets without recursion.