十进制转十六进制/****** Object: Function [dbo].[IntToHex] Script Date: 2013-10-30 16:22:15 ******/
USE [ZBP];
GO
SET ANSI_NULLS OFF;
GO
SET QUOTED_IDENTIFIER ON;
GO
CREATE FUNCTION [dbo].[IntToHex]
(@IntNum bigint)
RETURNS varchar(16)
AS
BEGIN
declare @Mods bigint, @res varchar(16)
set @res=''
while @IntNum <> 0
begin
set @Mods = @IntNum % 16
if @Mods > 9
set @res = Char(Ascii('A')+@Mods-10)+@res
else
set @res = Cast(@Mods as varchar(4))+@res
set @IntNum = @IntNum/16
end
return @res
END
GO
十六进制转十进制
/****** Object: Function [dbo].[HexToInt] Script Date: 2013-10-30 16:22:04 ******/
USE [ZBP];
GO
SET ANSI_NULLS OFF;
GO
SET QUOTED_IDENTIFIER ON;
GO
CREATE FUNCTION [dbo].[HexToInt]
(@hex varchar(100))
RETURNS int
AS
BEGIN
Declare @result bigint,@iPos int,@iTmp bigint,@iLoop int,@tmp varchar(16)
Set @tmp = '0123456789ABCDEF'
Select @result = 0,@iPos = 0
While @iPos < Len(@hex)
Begin
Set @iTmp =
CharIndex(substring(@hex,Len(@hex) - @iPos,1),@tmp)-1
Set @iLoop = 1
While @iLoop <= @iPos and @iTmp > 0
begin
Set @iTmp = @iTmp * 16
Set @iLoop = @iLoop + 1
end
Set @result = @result + @iTmp
Set @iLoop = @iLoop + 1
Set @iPos = @iPos + 1
End
return @result
END
GO
posted on 2013-11-08 16:54
Ke 阅读(1217)
评论(0) 编辑 收藏 所属分类:
sql server