calculator.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. {% extends 'index.html' %}
  2. {% block title %} Infinite Arbitrary Base Conversion Calculator {% end %}
  3. {% block main %}
  4. <div class="container-fluid">
  5. <h2>Infinite Arbitrary Base Conversion Calculator</h2>
  6. <form action="" method="GET" class="form-inline" role="form">
  7. {% if message %}
  8. <div class="bg-danger">Error in your calculation: {{ message }}</div>
  9. {% end %}
  10. {% for index, field in enumerate(form) %}
  11. <div class="form-group ' {{ ' has-error' if len(field.errors) > 0 else '' }}'">
  12. {% raw field.label(class_='control-label') %}
  13. <div>
  14. {% raw field(class_='form-control') %}
  15. {% for error in field.errors %}
  16. <div class="text-danger">
  17. {{ error }}
  18. </div>
  19. {% end %}
  20. </div>
  21. </div>
  22. {% if index == 1 %}
  23. <button class="btn btn-primary btn-sm" name="convert" value="down">Convert Down ↓</button>
  24. <br>
  25. {% elif index == 3 %}
  26. <button class="btn btn-primary btn-sm" name="convert" value="up">Convert Up ↑</button>
  27. {% end %}
  28. {% end %}
  29. </form>
  30. <br>
  31. <p>
  32. Examples:
  33. <ul>
  34. <li>01234567890abcdef</li>
  35. <li>0123456789abcdefghijklmnopqrstuvwxyz</li>
  36. <li>00123456789abcdefghijklmnopqrstuvwxyz (An extra 0 to keep the leading 0 but the mapping is no longer one-to-one!)</li>
  37. <li>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ</li>
  38. <li>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_</li>
  39. <li>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_</li>
  40. </ul>
  41. </p>
  42. <p>
  43. This is a form to convert numbers in arbitrary bases with no limits in integers. The computation is done on the server side.
  44. It uses the algorithm described in <a href="http://stackoverflow.com/a/1119769/1524507">here</a> except <code>rindex</code> is used instead for duplicate letters such as extra 0.
  45. Inspired by this <a href="http://elenzil.com/esoterica/baseConversion.html">JavaScript implementation</a>.
  46. </p>
  47. </div>
  48. {% block index_scripts %}{% end %}
  49. {% end %}