蠏貎朱Μ襯 伎伎 2讌 覲 企慨. 87企 螳 . 企ゼ 2讌襦 覲蠍 伎 れ螻 螳 螻一 伎 .
87/2 = 43, 襾語 = 1
43/2 = 21, 襾語 = 1
21/2 = 10, 襾語 = 1
10/2 = 5, 襾語 = 0
5/2 = 2, 襾語 = 1
2/2 = 1 襾語 = 0
蟆郁骸 1010111 = 26 + 24 + 22 + 21 + 20 = 64 + 16 + 4 + 2 + 1 = 87 伎 . 蟇 覦 企至 願屋 蟾? 覈 蠏貎朱Μ襯 伎覃 . れ るゼ ろ覃 蟆郁骸襯 詞 蟆企.
declare
@int int
, @bin varchar(100);
set @int = 87;
set @bin = '';
with dumy(no, mod, bin)
as
(
select 1, @int, convert(varchar, @int%2)
union all
select no + 1, @int/power(2, no), convert(varchar, (@int/power(2, no))%2)
from dumy
where no + 1 <=30
)
select
@bin = @bin + bin
from dumy
where mod + bin > 0
order by no desc
select @bin bin
/* result
bin
----------------------------------------------------------------------------------------------------
1010111
*/
螳讌 螻ろ伎 2讌襯 一危壱 る 蟆企. 蠏碁 2讌襯 る 覓語企 伎 . int 蠍 伎 31襴 覓語螳 . 碁企 ろ願鹸 讌襷.. ろ襴渚碁ゼ 襦 襷り碓 10讌 2讌 襷れ広 企 襷れ伎 蟯襴 覦覯 蟆. 谿瑚襦 襷れ広 企 れ螻 螳 襷る .
select colbin
into #bin
from (select '0' colbin union all select '1') t
select (b1.colbin + b2.colbin + b3.colbin) as bin_number
from #bin b1 cross join #bin b2 cross join #bin b3
order by 1;
/* result
bin_number
----------
000
001
010
011
100
101
110
111
*/