decToBase function
Convert stringDec
, the String representation of a decimal value (e.g.
"10"), to another base depending of the value of base
(E.g. 16 for
hexadecimal, 2 for binary, etc.).
Implementation
String decToBase(String stringDec, int base) {
var regExp = getBaseRegExp(10);
if (!regExp.hasMatch(stringDec)) return '';
var myString = '';
String restoString;
int resto;
var dec = int.parse(stringDec);
while (dec > 0) {
resto = (dec % base);
restoString = resto.toString();
if (resto >= 10) {
restoString = String.fromCharCode(resto + 55);
}
myString = restoString + myString; //aggiungo in testa
dec = dec ~/ base;
}
return myString;
}