

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is it possible to convert a number into other base forms using toString() method in JavaScript?
toString() method is not only used to convert an array into a string but also used to convert a number into other base forms. toString() method can output numbers from base 2 to base 36.
Lets' discuss it with an example
Example-1
In the following example, number 46 is converted into various base forms from 2 to 36.
<html> <body> <script> var Num = 26; document.write( "The number 26 can be converted in to" + "</br>" + "Binary - " + Num.toString(2) + "</br>" + "octal - " + Num.toString(8) + "</br>" + "Decimal - " + Num.toString(10) + "</br>" + "hexadecimal - " + Num.toString(16)); </script> </body> </html>
Output
The number 26 can be converted in to Binary - 11010 octal - 32 Decimal - 26 hexadecimal - 1a
Example-2
In the following example, number 36 is converted into binary, octal, decimal and hexadecimal base forms using toString() method.
<html> <body> <script> var Num = 36; document.write( "The number 36 can be converted in to" + "</br>" + " Binary - " + Num.toString(2) + "</br>" + " octal - " + Num.toString(8) + "</br>" + " Decimal - " + Num.toString(10) + "</br>" + " hexadecimal -" + Num.toString(16)); </script> </body> </html>
Output
The number 36 can be converted in to Binary - 100100 octal - 44 Decimal - 36 hexadecimal -24
- Related Questions & Answers
- Is it possible to override toString method in an array using Java?
- Convert Long into String using toString() method of Long class in java
- Convert a number into negative base representation in C++
- Java Program to convert Double into String using toString() method of Double class
- What is Natural Therapy? How is it different from other forms of medicines?
- What is filtered coffee? Is it any better than other forms of coffee?
- JavaScript RegExp toString() Method
- Convert one base to other bases in a single Java Program
- Is it possible to make a nested object immutable using Object.freeze() in JavaScript?
- Possible combinations and convert into alphabet algorithm in JavaScript
- Check if it is possible to convert one string into another with given constraints in Python
- Is it possible to create a new data type in JavaScript?
- Splitting number into n parts close to each other in JavaScript
- Is it possible to select text boxes with JavaScript?
- Is it possible to change the HTML content in JavaScript?
Advertisements