[java] Converting Hexadecimal String to Decimal Integer

Well, Mr.ajb has resolved and pointed out the error in your code.

Coming to the second part of the code, that is, converting a string with letters to decimal integer below is code for that,

import java.util.Scanner;

public class HexaToDecimal
{
   int number;

   void getValue()
   {
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter hexadecimal to convert: ");
      number = Integer.parseInt(sc.nextLine(), 16);
      sc.close();
   }

   void toConvert()
   {
      String decimal = Integer.toString(number);
      System.out.println("The Decimal value is : " + decimal);
   }

   public static void main(String[] args)
   {
      HexaToDecimal htd = new HexaToDecimal();
      htd.getValue();
      htd.toConvert();
   }
}

You can refer example on hexadecimal to decimal for more information.

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to hex

Transparent ARGB hex value How to convert a hex string to hex number Javascript: Unicode string to hex Converting Hexadecimal String to Decimal Integer Convert string to hex-string in C# Print a variable in hexadecimal in Python Convert ascii char[] to hexadecimal char[] in C Hex transparency in colors printf() formatting for hex Python Hexadecimal

Examples related to type-conversion

How can I convert a char to int in Java? pandas dataframe convert column type to string or categorical How to convert an Object {} to an Array [] of key-value pairs in JavaScript convert string to number node.js Ruby: How to convert a string to boolean Convert bytes to int? Convert dataframe column to 1 or 0 for "true"/"false" values and assign to dataframe SQL Server: Error converting data type nvarchar to numeric How do I convert a Python 3 byte-string variable into a regular string? Leading zeros for Int in Swift