我正在尝试编写接收整数作为输入并返回2的幂整数列表的ac#方法其总和等于输入整数将整数转换为按位后的个别幂的计算,其总和等于输出整数之和
例如
Input Integer :15
Output of this should be 1(2^0), 2 (2^1), 4 (2^2), 8 (2^3)
Sum of above integers is 15 = Input Integer
Input Integer :13
Output of this should be 1(2^0), 4 (2^2), 8 (2^3)
Sum of above integers is 13 = Input Integer
Input Integer :8
Output of this should be: 8 (2^3)
Sum of above integers is 15 = Input Integer
我可以知道一个好办法做到这一点?
回答你将如何检查是否有点'N'您输入的整数为1?为所有32个可能的位(提示:循环)做到这一点,你有你的答案。试一试,如果遇到问题,向我们展示代码并询问具体问题。 – oerkelens
给'BitArray'[机会](https://stackoverflow.com/questions/6758196/convert-int-to-a-bit-array-in-net)并根据需要格式化输出 – lokusking
请显示一些(不)你尝试过的工作代码。并开始看[如何问](https://stackoverflow.com/help/how-to-ask) –