--创建专用处理函数:
create function f_bin(@v varchar(20))
returns int
as
begin
declare @i int
declare @r int
set @v = left(@v+'00000000000000000000',20)
set @i = 1
set @r = 0
while(len(@v)>0)
begin
select @r = @r + (case substring(@v,1,4)
when '0000' then 0
when '0001' then 1
when '0010' then 2
when '0011' then 3
when '0100' then 4
when '0101' then 5
when '0110' then 6
when '0111' then 7
when '1000' then 8
when '1001' then 9
when '1010' then 10
when '1011' then 11
when '1100' then 12
when '1101' then 13
when '1110' then 14
when '1111' then 15
end) * power(16,5-@i)
set @v = stuff(@v,1,4,'')
set @i = @i + 1
end
return @r
end
我认为可以这样:
1.先补足20位 A=A+REPLICATE('0',20-LEN(A)),B=B+REPLICATE('0',20-LEN(B))
2.在循环逐位取ASCII值
declare @i int, @s varchar(20)
set @i=1
set @s=''
while i<=20
begin
SET @S=@S+CHAR((ASCII(SUBSTRING(A,i,1)))&(ASCII(SUBSTRING(B,i,1))))
SET @I=@I+1
end
SELECT @S