34,591
社区成员
发帖
与我相关
我的任务
分享
f object_id('fn_Num') is not null
drop function fn_Num
go
create function fn_Num(@Num int)
returns Table
as
return
(
with C1 as
(
select Power(2,0) as Num,ID=0,Num2=@Num&Power(2,0)
union all
select Power(2,ID+1) as Num,ID+1,@Num&Power(2,ID+1) from C1 where Power(2,ID+1)<=@Num
)
select Num2 from C1 where Num2>0
)
static void GetTwo(int num)
{
int max = 1;
if (num != 0)
{
while (max*2 <= num)
{
max = max * 2;
}
GetTwo(num - max);
Console.WriteLine(max);
}
}