Added to TW-Scripts On Friday, October 11, 2019 at 10:03:51 PM UTC+3:30, Mark S. wrote: > > > Here's how it works. To convert a number from base 10 to some other base, > first you divide the > initial number (dividend) by the new base (divisor). The result is the > quotient and the remainder. > You use the remainder as an index into your numerical symbol list > (0.1,2... etc.) to find the > first digit in the new base. You append that number to string that will > form your new number. > Then you take the quotient and repeat the process over and over until the > quotient is zero. > > The re-base macro creates the symbol list and sets up to call the base > converter macro (BCM). > The BCM, when called the first time, sets up an empty result string. > The BCM's outer list finds the remainder of the passed number divided by > the base and adds 1. > It adds one because the "nth" operator, used in a following step, starts > its index at "1" rather than zero. > > The BCM's 2nd, nested list finds the quotient from dividing the current > number by the base (divisor). > > The next, nested list breaks the symbol list into into its parts, finds > the symbol with the index determined by the > outer list, and then adds on the result string to the end of the new > symbol, forming the new result string. > > The fourth nested list checks if the quotient is zero. If so, it returns > the result and the macro is done. > > If the quotient is not zero, then the BCM macro recursively calls itself > again, passing in the base, the > new quotient, and the growing result string. > > I realize now that I probably should have just defined the base in the > re-base macro. Oh well. Probably > doesn't make much difference. > > > On Friday, October 11, 2019 at 6:45:12 AM UTC-7, @TiddlyTweeter wrote: >> >> In another thread Mark S. presented a magic macro to convert from decimal >> to other bases. >> >> I think its a rather marvellous bit of coding.* I have no idea how it >> works*, but it does work well. >> >>
-- 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/293c6df0-3cb6-45d1-95b4-49624da4b5b4%40googlegroups.com.

