- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert octal number to decimal number in Java
To convert octal to decimal number, use the Integer.parseInt() method with radix 8. Here, the radix is for Octal i.e. 8.
Let’s say we have the following octal string.
String myOctal = "25";
To convert it to decimal, use the Integer.parseInt() method.
int val = Integer.parseInt(myOctal, 8);
The following is the complete example.
Example
public class Demo { public static void main(String []args) { String myOctal = "25"; System.out.println("Octal = "+myOctal); int val = Integer.parseInt(myOctal, 8); System.out.println("Decimal = "+val); } }
Output
Octal = 25 Decimal = 21
Advertisements