ADVERTISEMENT
ADVERTISEMENT
Code Snippets JAVA Code Snippets

Java program to convert Hexadecimal String to Decimal Integer

By: IncludeHelp, On 02 OCT 2016

ADVERTISEMENT

In this code snippet/program we will learn how we can convert a hexadecimal string into its equivalent decimal integer.

In this program we will read a hexadecimal value using Scanner class and will convert entered hexadecimal value to integer value using Integer.parseInt() method.

//Java program to convert Hexadecimal String to Decimal Integer.

import java.util.Scanner;
 
class HexStringToInt
{
	public static void main(String args[])
	{
		String hex_value=null;
		int int_value=0;
		
		Scanner SC=new Scanner(System.in);
		
		//read hex value
		System.out.print("Enter value in hexadecimal: ");
		hex_value=SC.next();
		
		//converting it into integer
		int_value=Integer.parseInt(hex_value.trim(), 16 );
		
		//print values
		System.out.println("Integer value of: " + hex_value + " is: " + int_value);
		
		
	}
}

Output

Enter value in hexadecimal: 156AF
Integer value of: 156AF is: 87727
ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.