十进制数1 至100的二进制表示?

TSQL脚本。
declare @i int
declare @str varchar(8)
set @i=1
while @i<101
begin
declare @j int
set @str=''
set @j=1
while @j<=8
begin
  if @i & (power(2,@j-1))=(power(2,@j-1))
  set @str='1' + @str
  else
  set @str='0' + @str
  set @j=@j+1
end
print cast(@i as varchar(3))+'='+@str
set @i=@i+1
end

==results==

1=00000001
2=00000010
3=00000011
4=00000100
5=00000101
6=00000110
7=00000111
8=00001000
9=00001001
10=00001010
11=00001011
12=00001100
13=00001101
14=00001110
15=00001111
16=00010000
17=00010001
18=00010010
19=00010011
20=00010100
21=00010101
22=00010110
23=00010111
24=00011000
25=00011001
26=00011010
27=00011011
28=00011100
29=00011101
30=00011110
31=00011111
32=00100000
33=00100001
34=00100010
35=00100011
36=00100100
37=00100101
38=00100110
39=00100111
40=00101000
41=00101001
42=00101010
43=00101011
44=00101100
45=00101101
46=00101110
47=00101111
48=00110000
49=00110001
50=00110010
51=00110011
52=00110100
53=00110101
54=00110110
55=00110111
56=00111000
57=00111001
58=00111010
59=00111011
60=00111100
61=00111101
62=00111110
63=00111111
64=01000000
65=01000001
66=01000010
67=01000011
68=01000100
69=01000101
70=01000110
71=01000111
72=01001000
73=01001001
74=01001010
75=01001011
76=01001100
77=01001101
78=01001110
79=01001111
80=01010000
81=01010001
82=01010010
83=01010011
84=01010100
85=01010101
86=01010110
87=01010111
88=01011000
89=01011001
90=01011010
91=01011011
92=01011100
93=01011101
94=01011110
95=01011111
96=01100000
97=01100001
98=01100010
99=01100011
100=01100100
 

你可能感兴趣的:(十进制数1 至100的二进制表示?)