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
  • 相关阅读:
    我用自己做的图书比价搜索买了一本书
    2.17
    最近的工作
    FireBug的Bug
    2.18
    tecent面试题解答
    .net杂记
    python的round测试
    最近在网上买书的体会
    关于迅雷评论的一个改造html css
  • 原文地址:https://www.cnblogs.com/Fandyx/p/1988073.html
Copyright © 2011-2022 走看看