Home Java Java-conversion Convert Hexadecimal to Decimal

Related Tutorials


 
 

Share on Google+Share on Google+

Convert Hexadecimal to Decimal

Advertisement
In this section, you will learn to change hexadecimal number into decimal.

Convert Hexadecimal to Decimal

     

In this section, you will learn to change hexadecimal number into decimal. The java.lang package provides the functionality to convert a hexadecimal number into decimal.

Code Description:

This program takes a hexadecimal number at console and converts it into a decimal number using parseInt() method. This method parses the string value as a signed integer in the radix specified by the second argument. Here the second argument is 16  to convert a hexadecimal into a decimal number. 

parseInt():
This method takes two arguments: hexadecimal and 16. It converts a hexadecimal number into a decimal number. 

Here is the code of this program:

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

public class  HexadecimalToDecimal{
  public static void main(String[] argsthrows IOException{
  BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter the Hexadecimal number:");
  String str= bf.readLine();
  int i= Integer.parseInt(str,16);
  System.out.println("Decimal:="+ i);
  }
}

Download this program:

Output  of this program.

C:\corejava>java HexadecimalToDecimal
Enter the Hexadecimal number:
32
Decimal:=50
C:\corejava>
Advertisement

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 Hexadecimal to Decimal   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:4
Lucky
June 19, 2011
cs/it hehe

xplain it sir please asap ...
kopuri
November 30, 2011
regarding code

can u explain clearly how its converts?????
gerald alcedera
January 10, 2012
object oriented programming

how will you determine the legal hexadecimal if the user inputed an ilegal hexadecimal or decimal?
Birendra
May 12, 2012
Nice Java solutions

Your Java solutions are always straight and simple. It helps a lot. Thanks a lot to Rose India team. Thanks, Birendra
DMCA.com