Next, lets try converting a number from decimal to different bases (that ‘var n’ statement is required). The ‘toString(base)’ method can be invoked on any number and it takes the parameter base to which the actual number should be converted. In the first case it is evident that I am converting from decimal to binary format, then to octal and hexadecimal.
Next, Converting from one base to other is a two step process
- convert from <any> base to decimal using parseInt method
- convert from decimal to <any> other base