Re: A92: Binary and Decimil Conversion


[Prev][Next][Index][Thread]

Re: A92: Binary and Decimil Conversion




>i know i shouldn't do this...but i have to gloat
>this was posted on the 82 list originally, and since i made the program
>on the 92, i had to post it here.
>
>decimal(a,b,c):func
>local d,e,f,g,h
>0->e:""->g:if b=10 then:expr(a)->e:goto skip:endif
>for h,1,dim(a)
> ord(mid(a,h,1))-48->d:if d>9:d-7->d
> if d>35:d-6->d:e+d*b^(dim(a)-h)->e
>endfor:lbl skip
>ceiling(log(e)/log(c))+1->f:if c=10:return string(e)
>for h,f-1,0,-1
> int(e/c^h)->d:e-d*c^h->e
> if d>9:d+7->d:if d>42:d+6->d
> g&char(d+48)->g
>endfor:return g
>endprgm
>
>this program translates "a" string from the current "b" integer type
>(binary=2, decimal=10...etc.  2-63 is the range) to a different "c"
>integer type...so to change 10 decimal into binary do the following:
>decimal("10",10,2) and it returns "0A" i believe
>
>hope this helps some people...if not then flame me

I like it.  Nice way to interface it.  My own little personal conversion app
is a little more tricky to use...  Good job! :)

l8r
MikeM