Answers for "hex string to int java"

5

Java convert hex to decimal

public class ConvertHexToDecimal
{
   public static void main(String[] args)
   {
      String strHex = "b";
      int decimal = Integer.parseInt(strHex, 16);
      System.out.println("Decimal number : " + decimal);
   }
}
Posted by: Guest on December-29-2020
1

String to hexadecimal in java

// String to hexadecimal in java
import java.util.Scanner;
public class StringToHexJava
{
   public static void main(String[] args)
   {
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter a string: ");
      String strInput = sc.next();
      StringBuffer sb = new StringBuffer();
      char[] chArray = strInput.toCharArray();
      for(int a = 0; a < chArray.length; a++)
      {
         String strHexadecimal = Integer.toHexString(chArray[a]);
         sb.append(strHexadecimal);
      }
      String strOutput = sb.toString();
      System.out.println(strOutput);
      sc.close();
   }
}
Posted by: Guest on February-18-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language