This base converter will convert any positive decimal number to any other base less than base 10. It uses the modular arithmetic function to calculate each digit in the given base. Bases above base 10 are not supported due to the lack of an easy way of adding transdecimal digits in Scratch. Javascipt code for those interested: var originalInput = prompt("What decimal number would you like to convert?"); var input = originalInput; var wasNegative = false; if (originalInput<0) { input = Math.abs(input); wasNegative = true; } var base = 0 while (base < 2 || base > 10) { base = prompt("What sub-decimal base would you like to convert it to?"); if (base < 2 || base > 10) { alert("I can't convert into base " + base + "."); } } var placeValue = 1; var output = 0; while (input) { output += ((input%base)*placeValue); input -= input%base; input = input/base; placeValue = placeValue*10; } if (wasNegative) { output = "-" + output; } alert(originalInput + " in base " + base + " is " + output + ".");
Put in any decimal number and this base converter will convert it to the sub-decimal base of your choice.