zoukankan      html  css  js  c++  java
  • Hexabecimal turn to Decimal custom functions

    The following is a Hexadecimal turn to Decimal system custom functions.

    wrote by Jimmy on Mar 18th 2011

    use master
    GO

    drop function [dbo].[Jimmy_HexadecimalToDecimal]
    go

    create function [dbo].[Jimmy_HexadecimalToDecimal]
    (
    @hec varchar(50)
    )
    returns int
    as
    begin
    declare @dec int,@count int,@bigbit int,@strone int

    set @bigbit = 0
    set @count = 1
    set @dec = 0

    --get the number of hexadecimal digits
    while @bigbit < len(@hec)
    begin
    set @strone = ascii(lower(substring(@hec,@count,1)))
    if (@strone >= 48 and @strone <= 57)
    or
    (
    @strone >= 97 and @strone <= 102)
    begin
    set @bigbit = @bigbit + 1
    set @count = @count + 1
    continue
    end
    else
    break
    end

    set @count = 1

    while @bigbit > 0
    begin
    set @strone =ascii(lower(substring(@hec,@count,1)))
    select @dec = @dec +
    cast(
    case when @strone >=48 and @strone <= 57 then @strone-48
    when @strone = 97 then 10
    when @strone = 98 then 11
    when @strone = 99 then 12
    when @strone = 100 then 13
    when @strone = 101 then 14
    when @strone = 102 then 15
    end
    as int)*power(16,@bigbit-1)
    set @count = @count + 1
    set @bigbit = @bigbit - 1
    end

    return @dec
    end
    go
    ----------------------
    select [master].[dbo].[Jimmy_HexadecimalToDecimal] ('ab') as '十六进制转十进制' --171
    go
  • 相关阅读:
    Synplify9.6.2破解(转帖)
    让博客园博客自动生成章节目录索引
    如何学好FPGA
    verilog 不可综合语句
    在FPGA中使用for循环一定浪费资源吗?
    在verilog中调用VHDL模块
    C#和Java中执行SQL文件脚本的代码(非常有用)
    C#通用JSON帮助类
    公共的Json操作C#类
    Calendar.NET
  • 原文地址:https://www.cnblogs.com/Fandyx/p/1988073.html
Copyright © 2011-2022 走看看