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');
}