SQL之36進製轉換成10進製資料

2021-05-04 21:11:18 字數 883 閱讀 7092

--建立人  :鄭紫至

--建立日期:2009-9-10

--引數描述:@strhex36 被轉換36進製字串

--測試方法:select dbo.converthex36to10('a6zq2')

create function dbo.converthex36to10

(@strhex36 varchar(100))

returns int

asbegin

declare @strhex36len int       --被轉換36進製字串的長度

declare @base36to10  int       --每位36進製基數對應的10進製資料大小

declare @index       int       --字串索引

declare @hex10       int       --被返回10進製資料

declare @base36      varchar(1)--36進製基數

set @hex10=0

set @strhex36len=len(@strhex36)

set @index=1

while @index<=@strhex36len

begin

set @base36=substring(@strhex36,@index,1)

set @base36to10=charindex(@base36,'0123456789abcdefghijklnmopqrstuvwxyz')-1

set @hex10=@hex10+@base36to10*power(36,@strhex36len-@index)

set @index=@index+1

endreturn   @hex10

end

SQL之10進製轉換成36進製資料

建立人 鄭紫至 建立日期 2009 9 10 引數描述 hex10 被轉換10進製數字 測試方法 select dbo converthex10to36 17122394 create function dbo converthex10to36 hex10 int returns varchar 1...

任意進製轉換10進製和10進製轉換成任意進製

原理 輸入是乙個字串,由函式體轉換成數 考慮是否溢位int範圍 include using namespace std include typedef long long ll 這個具體要看要求,如果給的輸入是否會超過乙個int的範圍 include ll transdec string num,i...

10進製數轉換成16進製制

十六進製制的元素個數固定,而且還有對應編號,可以用查表法.乙個int型別十進位制數在32位作業系統中佔4個位元組,32位2進製數取它的低8位,例如60,在記憶體中以二進位制數0011 1100存放,而乙個十六進製制數中每一位數對應二進位制中4位數,因此可以將十進位制數與f進行 與 運算,得出低四位 ...