I quickly wrote a method that does exactly what you want, certainly not the best though:
public static List<int> DecomposeBitFlag(int flag) {
var bitStr = Convert.ToString(flag, 2);
var returnValue = new List<int>();
for(var i = 0 ; i < bitStr.Length ; i++) {
if (bitStr[bitStr.Length - i - 1] == '1') {
returnValue.Add((int)Math.Pow(2, i));
}
}
return returnValue;
}
How it works:
I first convert the integer parameter to a binary string. For each of the "1"s in the string, add 2 to the power i to the return value list. i is the index of the "1" in the reversed string.
EDIT:
If you only want to know the number of bits, this will do:
public static int BitFlagBitCount(int flag) {
var bitStr = Convert.ToString(flag, 2);
return bitStr.Count(c => c == '1');
}