0
我有一個存儲十六進制的char(32)列。我需要將這個十六進制數字轉換爲十進制,如十進制(40,0),因爲無符號的bigint不足以容納這個長度爲32個字符的十六進制。我找不到一種方法來做這個約定,十六進制到十進制。Sybase數據轉換
任何人都請提前幫助,謝謝! Db的
對不起,這是Sybase ASE 15
我有一個存儲十六進制的char(32)列。我需要將這個十六進制數字轉換爲十進制,如十進制(40,0),因爲無符號的bigint不足以容納這個長度爲32個字符的十六進制。我找不到一種方法來做這個約定,十六進制到十進制。Sybase數據轉換
任何人都請提前幫助,謝謝! Db的
對不起,這是Sybase ASE 15
不是最優雅的解決方案 - 會更好地使用一個循環,而不是代碼 重複行 - 甚至只是通過使用塊減少線4個字符的子字符串,而不是一次一個字符
此解決方案假設十六進制字符串被完全填充(如果它們是空白填充的,則需要執行一些額外的操作來解析字符串並獲取字節進入正確的桶)
但基本上,這是這個想法:
create variable h varchar(32);
set h = 'FEDCBAFEDCBA';
create variable a decimal(40,0);
set a =
hextoint(substr(h,1,1))*power(16,31)+
hextoint(substr(h,2,1))*power(16,30)+
hextoint(substr(h,3,1))*power(16,29)+
hextoint(substr(h,4,1))*power(16,28)+
hextoint(substr(h,5,1))*power(16,27)+
hextoint(substr(h,6,1))*power(16,26)+
hextoint(substr(h,7,1))*power(16,25)+
hextoint(substr(h,8,1))*power(16,24)+
hextoint(substr(h,9,1))*power(16,23)+
hextoint(substr(h,10,1))*power(16,22)+
hextoint(substr(h,11,1))*power(16,21)+
hextoint(substr(h,12,1))*power(16,20)+
hextoint(substr(h,13,1))*power(16,19)+
hextoint(substr(h,14,1))*power(16,18)+
hextoint(substr(h,15,1))*power(16,17)+
hextoint(substr(h,16,1))*power(16,16)+
hextoint(substr(h,17,1))*power(16,15)+
hextoint(substr(h,18,1))*power(16,14)+
hextoint(substr(h,19,1))*power(16,13)+
hextoint(substr(h,20,1))*power(16,12)+
hextoint(substr(h,21,1))*power(16,11)+
hextoint(substr(h,22,1))*power(16,10)+
hextoint(substr(h,23,1))*power(16,9)+
hextoint(substr(h,24,1))*power(16,8)+
hextoint(substr(h,25,1))*power(16,7)+
hextoint(substr(h,26,1))*power(16,6)+
hextoint(substr(h,27,1))*power(16,5)+
hextoint(substr(h,28,1))*power(16,4)+
hextoint(substr(h,29,1))*power(16,3)+
hextoint(substr(h,30,1))*power(16,2)+
hextoint(substr(h,31,1))*power(16,1)+
hextoint(substr(h,32,1))*power(16,0);