zoukankan      html  css  js  c++  java
  • 将十进制转成十六进制

    --创建函数

    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

    */

  • 相关阅读:
    VMware Workstation的三种网络连接方式
    sql:unix下的sql操作
    linux脚本: makefile以及链接库
    unix shell: ksh fundamental(Korn Shell)
    linux c: core dump
    linux命令:scp
    Eclipse更改默认工作目录的方法
    linux: 可重入函数与不可重入函数
    linux环境 :Linux 共享库LIBRARY_PATH, LD_LIBRARY_PATH 与ld.so.conf
    linux命令:Linux命令大全
  • 原文地址:https://www.cnblogs.com/accumulater/p/6244455.html
Copyright © 2011-2022 走看看