http://xiangai.taobao.com
http://shop148612228.taobao.com

十进制转三十六进制,10进制转36进制

sql server版本:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[ufn_ConvertIntTo36Scale] ( @Num BIGINT )
RETURNS VARCHAR(500)
AS
BEGIN
/**************************************
-- 功能:十进制转三十六进制,10进制转36进制
**************************************/
DECLARE @Result VARCHAR(500);
SET @Result = '';
WHILE ( @Num > 0 )
BEGIN
SET @Result = SUBSTRING('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
@Num % 36 + 1, 1) + @Result;
SET @Num = @Num / 36;
END;
RETURN @Result;
END;

C#版本:

/// </summary>
/// <param name="s"></param>
/// <param name="length"></param>
/// <returns></returns>
public static String ConvertIntTo36Scale(this int s, int length = 6)
{
string Result = "";
while (s > 0)
{
Result = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".Substring(s % 36, 1) + Result;
s = s / 36;
}
return Result.PadLeft(length, '0');
}

posted @ 2017-11-29 16:47  万事俱备就差个程序员  阅读(1980)  评论(0编辑  收藏  举报

http://xiangai.taobao.com
http://shop148612228.taobao.com
如果您觉得对您有帮助.领个红包吧.谢谢.
支付宝红包
微信打赏 支付宝打赏