Home Java Java-conversion Convert Octal to Decimal

Related Tutorials


 
 

Share on Google+Share on Google+

Convert Octal to Decimal

Advertisement
In this section, you will learn to convert an octal number to decimal. The following program helps you converts number octal to decimal.

Convert Octal to Decimal

     

In this section, you will learn to convert an octal number to decimal. The following program helps you converts number octal to decimal. 

Description of code:

This program takes an octal number at console converts it into decimal number using parseInt() method. This method parses the string value as a signed integer in the radix specified by the second argument as 8. And you get the decimal number.

Integer.parseInt(oct, 8): This method takes an int value in a string format and it returns an Integer object. It converts an octal number into decimal and takes two parameters. First argument passed is a specified String which is  parsed using the radix given through the second argument. The first parameter interprets as representing a signed integer in the radix specified by the second parameter.

Use Keyboard  as :S- This is a string to be parsed.
Radix (as a use integer value):- The radix represents an integer value to be parsed in the interpreting string.

Here is the code of this program:

import java.io.*;
import java.lang.*;

public class  OctalToDecimal{
  public static void main(String[] args)throws IOException{
  BufferedReader reader = 
  new 
BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter the octal number:");
  String oct = reader.readLine();
  int i= Integer.parseInt(oct,8);
  System.out.println("Decimal:=" + i);
  }
}

Download this program.

 Output of this program:

C:\corejava>java OctalToDecimal
Enter the octal number:
32
Decimal:=26
C:\corejava>_

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 31, 2007

Related Tutorials

Discuss: Convert Octal to Decimal   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
benjamin
June 23, 2011
writig program which display octa to hexa decimal

thank you for your help
renaefushay
February 9, 2012
information technology

i want to learn how to convert from octal to binary.
DMCA.com