Convert a number to a different base.
- //Convert a number to a different base (e.g., from hex to decimal)
- function changeBase(num, from, to)
- if(isNaN(from) || from < 2 || from > 36 || isNaN(to) || to < 2 || to > 36)
- throw (new RangeError("Illegal radix. Radices must be integers between 2 and 36, inclusive."));
- num = parseInt(num, from); //convert to decimal
- num = num.toString(to); //convert the decimal to desired base
- return num.toUpperCase();
CommentsSubscribe to comments
You need to login to post a comment.