• 将十进制转成十六进制


    --创建函数

    create function  [dbo].[hex](@cardno int )

    returns varchar (100)

    as

    begin

        declare  @temp_mod int

        declare  @i int

        declare  @result varchar(100)

        declare  @temp_x int

        declare  @result_values int

        set  @result=''

        set  @i=1

        set  @temp_x=0

    while  @cardno>0

        begin

           set  @temp_mod=@cardno%16

           set  @cardno=@cardno/16

           set  @result=(case  @temp_mod when  10 then  'A'

                                      when  11 then  'B'

                                      when  12 then  'C'

                                      when  13 then  'D'

                                      when  14 then  'E'

                                      when  15 then  'F'

                                      else  ltrim(str(@temp_mod)) end  )+@result

        end

    return @result

    end

     

    --测试示例

    select [dbo].[hex](1808) as Hex

     

    --运行结果

    /*

    Hex

    ----------

    710

    */

    --第二版

    /****************************

      整数转换成进制

      作者:不得闲

      QQ: 75492895

      Email: appleak46@yahoo.com.cn

    ****************************/

    Go

    Create Function IntToHex(@IntNum int)

    returns varchar(16)

    as

    begin

      declare @Mods int,@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

     

    --测试示例

    select dbo.IntToHex(1808)

     

    --运行结果

    /*

    710

    */

  • 相关阅读:
    建立自己的开发知识库?分享制作电子书的经验
    海量Office文档搜索
    为什么要检测数据库连接是否可用
    多年的.NET开发,也只学会了这么几招
    总结一下ERP .NET程序员必须掌握的.NET技术
    菜单设计器(Menu Designer)及其B/S,C/S双重实现(B/S开源)
    软件公司为什么要加密源代码
    .NET开发中经常用到的扩展方法
    在Win8 Mertro 中使用SQLite
    SQLite
  • 原文地址:https://www.cnblogs.com/accumulater/p/6244455.html
Copyright © 2020-2023  润新知