日期:2014-05-18  浏览次数:21044 次

把6个1转成2进制是多少?


在SLQ把6个1转成2进制是多少?


------解决方案--------------------
SQL code

--十进制转二进制函数
create function dbo.inttobit (@number int)
returns varchar(100)
as
begin
    declare @i int
    declare @j float
    declare @m int
    declare @out1 varchar(1)
    declare @out2 varchar(20)
    set @i=@number
    set @out2=' '
    while @i>=1
    begin 
    set @j=@i/2
    set @m=@i%2
    set @i=floor(@j)
    set @out1=cast(@m as char(1))
    set @out2=@out1+@out2
    end
    return @out2
end

select dbo.inttobit(111111)
/*
11011001000000111 
*/