用一个语句判断一个整数是不是二的整数次幂
#define Is2Integer(n) ((n&(n-1))?0:1)
//用一个语句判断一个整数是不是二的整数次幂
[解决办法]
select
case when 数值 /2 =(数值+1)/2 then 'true' else 'false' end
from
表
[解决办法]
啥叫整数次幂?1,2,4,8,16? 直接看%2就是了
[解决办法]
select case when CONVERT(INT,log(16)/log(2))=log(16)/log(2) then '整除' ELSE '不整除' END
------
整除
(所影响的行数为 1 行)
1> declare @x int;
2> set @x=10;
3> select case when replace(substring(master.dbo.fn_varbintohexstr(CONVERT(VARBI
NARY(16),@x)),3,10),'0','') in ('','1','2','4','8') then 'OK' else 'FALSE' end
4>
5> go
-----
FALSE
(1 rows affected)
1> declare @x int;
2> set @x=64;
3> select case when replace(substring(master.dbo.fn_varbintohexstr(CONVERT(VARBI
NARY(16),@x)),3,10),'0','') in ('','1','2','4','8') then 'OK' else 'FALSE' end
4> go
-----
OK
(1 rows affected)
1>
declare @i int
set @i = 128
select case when(select count(1) from master..spt_values where number =log(@i)/log(2)) !=0
then '整除'
else '非整除'
end