User:Mattflaschen/decimal to binary

2

Description
This will convert a decimal numeral into a binary one. For example:
 * produces:

and
 * produces:

Because templates do not allow internal variables, the template calculates every digit of the result independently then simply concatenates them together. This means the value of higher digits must always be subtracted using the mod operator. Then, the remaining value is divided by the appropriate power of 2, then truncated to 0 or 1. Because the truncation sometimes returns floating point values instead of 1 (e.g. .999999901), it was necessary to correct this by assigning either 1 or 0 with ifexpr, depending on whether the value is greater than 0.5.