For converting back to base 10. Just barely tested. Seems to work.

Usually converting from base x to base 10 would be easier than the other 
way around. But
the lack of a power function and an easy way to index an array meant that 
this was
actually harder, somehow.


\define base-deconverter(num,exp,result:"")
<$list filter="[<__num__>split[]last[]]" variable="sym">
<$list filter="[<__num__>split[]butlast[1]join[]]" variable="next">
<$list filter="[enlist:raw<syms>allbefore<sym>count[]]" variable="num">
<$list filter="[enlist:raw<__exp__>product[]multiply<num>add<__result__>]" 
variable="result">
<$list filter="[<__exp__>addsuffix[ ]addsuffix<base>]" variable="exp" >
<$list filter="[<next>!is[blank]]" emptyMessage=<<result>>>
<$macrocall $name="base-deconverter" num=<<next>> exp=<<exp>> result=<<
result>> />
</$list>
</$list>
</$list>
</$list>
</$list>
</$list>
\end

\define tobase10(num,base)
<$vars
syms="0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y 
Z"
base=<<__base__>>
>
<<base-deconverter $num$  "1"  >>
</$vars>
\end

<<tobase10 133 5>>




-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/ddc8d1be-8b61-4547-a60e-ec3d3c5942a2%40googlegroups.com.

Reply via email to