programming-examples/js/Math/Convert a number from one base to another .js

10 lines
405 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
var base_convert = function(number, initial_base, change_base) {
if ((initial_base && change_base) <2 || (initial_base && change_base)>36)
return 'Base between 2 and 36';
return parseInt(number + '', initial_base)
.toString(change_base);
}
console.log(base_convert('E164',16,8));
console.log(base_convert(1000,2,8));