Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Convert Hexadecimal to Decimal 
 

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>

                         

» View all related tutorials
Related Tags: java c ide array class div io matrix get vi this id define ping for program to learn ram ear

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

3 comments so far (
post your own) View All Comments Latest 10 Comments:

pls giv me a code that will convert a hexadecimal to a decimal.You are to implement a Number System Converter program using java or c/c++. Your program must at least satisfy the requirements below: User Input:  Input a HEXADECIMAL number.  Select between operation: (a) multiplication OR (b) addition. Process  You have to implement two different methods in converting the number.  Method 1: o Uses the usual technique in computing for the equivalent of the number. o In this method, depending on the position in the string, each digit has an associated value of an integer raised to the power of 16. The total sum of the values for each of the digits generates the decimal equivalent of the input value. o Ex. 3A2(base16) = (3x16^2) + (10x16^1) + (2x16^0) = o In short, the function must require an input parameter, performs the (usual) conversion and outputs the result of the function.  Method 2: o The second method prohibits the use of multiplication and exponential function. Thus, you can implement the program that uses repeated addition every time you need to find the product or power of a number. o Ex. 21B (base16) = [(16+16+16+16+16+16+16+16+16+16+16+16+16+16+16+16) +(16+16+16+16+16+16+16+16+16+16+16+16+16+16+16+16)] +[(16)] +[(11)] = 539 o You can create another function that will perform the repeated addition operation that substitutes the multiplication operation. Program Output  Display the STEP-BY-STEP SOLUTION in converting a HEX-to-DEC.  The program must have a COUNTER that will serve as an indicator of the number of steps needed before the program terminates.  And the equivalent DECIMAL NUMBER of the input value.

Posted by Cabrera on Sunday, 11.25.07 @ 15:20pm | #40012

pls send the code to this e-mail add. .. pls pls

claudine_214@yahoo.com

Posted by Cabrera on Friday, 11.23.07 @ 11:38am | #38594

my comments is to convert Hexadecimal to decimal in Java program without predefined statement in a program, please show me the program without predefined statement. thnk u

Posted by jezer ballados on Monday, 10.22.07 @ 05:26am | #34538

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.