1. Submitted for Your Improvement
- Posted by C & K L <candkNOSPAM2ME at TICNET.COM> Dec 02, 1998
- 411 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
2. Re: Submitted for Your Improvement
- Posted by isaac <isaaca at MINDSPRING.COM> Dec 02, 1998
- 395 views
- Last edited Dec 03, 1998
not sure which is faster, but I'd probobly just use: include get.e function dec_to_hex(atom dec) return sprintf("%x",dec) end function function hex_to_dec(sequence hex) sequence val val=value('#'&hex) return val[2] end function
3. Re: Submitted for Your Improvement
- Posted by C & K L <candk at TICNET.COM> Dec 02, 1998
- 394 views
- Last edited Dec 03, 1998
I knew this would happen... Thanks, isaac! isaac wrote: > > not sure which is faster, but I'd probobly just use: > > include get.e > > function dec_to_hex(atom dec) > return sprintf("%x",dec) > end function > > function hex_to_dec(sequence hex) > sequence val > val=value('#'&hex) > return val[2] > end function
4. Re: Submitted for Your Improvement
- Posted by "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> Dec 04, 1998
- 397 views
On Wed, 2 Dec 1998, C & K L wrote: > --hex.e Nice code. Why the reversal though? Why not just parse right to left? See my basebag.e (needs my get2.e) or get my projects.zip (that has basebag.e, get2.e and tonnes of other stuff in it) [My_H.->Eu.->Projects_Archive] basebag.e handles any base from 2 to 36 and even copes with floating point numbers. *** My messages seem to be taking a very long time to reach you people out there in Euphorialand... Must be something between the UK academia and the US. This message posted about 0955hrs-04Dec1998. Starting stopwatch... -- Carl R White -- Final Year Computer Science at the University of Bradford E-mail...: cyrek- at -bigfoot.com -- Remove the hyphens before mailing. Ta :) URL......: http://www.bigfoot.com/~cyrek/ Ykk rnyllaqur rgiokc cea nyemdok ymc giququezka caysgr -- B.Q.Vgesa
5. Re: Submitted for Your Improvement
- Posted by "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> Dec 04, 1998
- 386 views
I wrote: > My messages seem to be taking a very long time to reach you people out ... > US. This message posted about 0955hrs-04Dec1998. Starting stopwatch... Stopping stopwatch at 1035hrs, same day. Hmm. Problem gone. Sorry for the wasted bandwidth. .sig snipped to make up :) -- Carl R White -- Final Year Computer Science at the University of Bradford