Submitted for Your Improvement
- Posted by C & K L <candkNOSPAM2ME at TICNET.COM> Dec 02, 1998
- 548 views
--hex.e global constant HEX="0123456789ABCDEF" global function backwards(sequence s) --replace with Rob's faster reverse sequence s1 s1={} for t=1 to length(s) do s1=append(s1,s[length(s)-t+1]) end for return s1 end function global function hex_to_dec(sequence hex) atom dec dec=0 --reverse order of sequence hex hex=backwards(hex) --change hex to a decimal for t= 1 to length(hex) do dec=dec+((find(hex[t],HEX)-1)*power(16,t-1)) end for return dec end function global function dec_to_hex(atom dec) sequence hex atom inside,rdec hex={} inside=0 --change dec to hex for t= 4 to 1 by -1 do rdec=floor(dec/power(16,t)) if rdec > 0 then hex=append(hex,HEX[rdec+1]) dec=remainder(dec,power(16,t)) inside=1 elsif rdec=0 and inside then hex=append(hex,HEX[rdec+1]) end if end for hex=append(hex,HEX[dec+1]) return hex end function Thanks in advance for the improvement suggestions!ck