用一个语句判断一个整数是不是二的整数次幂,该怎么解决
用一个语句判断一个整数是不是二的整数次幂
#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就是了
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
最多到2的2048次方验证。再大,就得另外想折了..
------解决方案--------------------
#define Is2Integer(n) ((n&(n-1))?0:1)
//用一个语句判断一个整数是不是二的整数次幂
是一个好方法,只不过有一定的范围!!
------解决方案--------------------
log(2,int) is int? true : false
具体语法忘了 查manual
------解决方案--------------------
关注……
关注……
------解决方案--------------------
log(@input)/log(2)
#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
最多到2的2048次方验证。再大,就得另外想折了..
------解决方案--------------------
#define Is2Integer(n) ((n&(n-1))?0:1)
//用一个语句判断一个整数是不是二的整数次幂
是一个好方法,只不过有一定的范围!!
------解决方案--------------------
log(2,int) is int? true : false
具体语法忘了 查manual
------解决方案--------------------
关注……
关注……
------解决方案--------------------
log(@input)/log(2)