short days = 80; short[] possibleDays = new short[] { 1, 2, 4, 8, 16, 32, 64 };
2^0=1, 2^1=2, 2^2=4, 2^3=8, 2^4=16, 2^5=32, 2^6=64
for (i=1; i<=64; i<<=1) if (day & i) printf(%d ", i);
Console.WriteLine("Enter Input:"); string input = Console.ReadLine(); double days = Convert.ToDouble(input); //short days = 80; short[] possibleDays = new short[] { 1, 2, 4, 8, 16, 32, 64 }; short sum = 0; string totalValues = string.Empty; for (int i = possibleDays.Length; i >= 1; i--) { sum += possibleDays[i - 1]; if (sum == days) { totalValues += possibleDays[i - 1] + ";"; break; } else { if (sum > days) { sum -= possibleDays[i - 1]; } else { totalValues += possibleDays[i - 1] + ";"; } } } totalValues = totalValues.TrimEnd(';'); Console.WriteLine(totalValues); Console.ReadKey();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)