10进制与36进制的转换函数

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


-- =============================================
-- AUTHOR: <ZHYD>
-- CREATE DATE: <2010-03-12>
-- DESCRIPTION: <十进制转换成36进制>
-- =============================================

ALTER function [dbo].[fn_10to36] (
@i int
)
returns varchar(30)
as
begin

declare @r varchar(30)
set @r= ''

declare @m int
declare @s int
set @s=@i
while @s> =36
begin
set @m=@s % 36
set @r=case when @m <10 then cast(@m as varchar)
else cast(char(ascii( 'A')+@m-10) as varchar) end+@r
set @s=@s/36
end
if @s> 0 or (@s=0 and @r= '')
set @r=case when @s <10 then cast(@s as varchar)
else cast(char(ascii( 'A')+@s-10) as varchar) end+@r
return @r
end




set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


-- =============================================
-- AUTHOR: <ZHYD>
-- CREATE DATE: <2010-03-12>
-- DESCRIPTION: <36进制转换成10进制>
-- =============================================

ALTER function [dbo].[fn_36to10] (
@str varchar(30)
)
returns int
as
begin

declare @returnValue int
select @returnValue = 0
declare @str36 varchar(32)
declare @subWork varchar(1)
declare @workIndex int
select @str36 = '123456789ABCDEFGHIJKLMNOPQRSTUVWSYZ'

declare @len int
declare @i int
select @i = 1
select @len = datalength(@str)

while (@i <= @len)
begin
select @subWork = SUBSTRING(@str, @i, 1)
select @workIndex = charindex( @subWork, @str36)
select @returnValue = @returnValue + (@workIndex * power(36, @len-@i))
select @i = @i + 1
end

return @returnValue
end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值