十进制整型转二进制字符串(锁定字符串长的最小值)

 

 1set ANSI_NULLS ON
 2set QUOTED_IDENTIFIER ON
 3go
 4
 5-- =============================================
 6-- Author:        HuntFox
 7-- Create date: 2005.11.23
 8-- Description:    十进制整型转二进制字符串(锁定字符串长的最小值)
 9-- =============================================
10ALTER FUNCTION [dbo].[ToBinarySystemString] 
11(
12@DecimalSystemInt int,
13@BinarySystemStringLen int
14)
15RETURNS NVARCHAR(31)
16AS
17BEGIN
18-- Declare the return variable here
19declare @ResultVar varchar(31)
20set @ResultVar=''
21while (@DecimalSystemInt<>0)
22begin
23   set @ResultVar=@ResultVar+convert(char(1),@DecimalSystemInt%2)
24   set @DecimalSystemInt=@DecimalSystemInt/2
25end
26set @ResultVar=REVERSE (@ResultVar)
27while (Len(@ResultVar)<@BinarySystemStringLen)
28begin
29set @ResultVar='0'+@ResultVar
30end
31RETURN @ResultVar
32END
33
34
35
36
37
38
39
40

 

 

 

 

posted @ 2005-11-23 15:54  .NetFox  阅读(456)  评论(0)    收藏  举报