not the most elegant solution
- would be better to use a loop instead of repeated lines of code
- or even just reduce the lines by using blocks of 4-character substring, instead of 1 character at a time
also this solution assumes hexadecimal strings are completely filled (if they are blank-padded, some additional gymnastics would have to be performed to parse the string up and get the bytes into the correct buckets)
but fundamentally, this is the idea:
create variable h varchar(32);
set h = 'FEDCBA9876543210FEDCBA9876543210';
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);