Sunday 26 May 2019

Java: Convert hexa string to integer


'Integer.parseInt(hexaString, 16);' converts hexa string to decimal integer.

Example
String hexaString = "ff";
int number = Integer.parseInt(hexaString, 16);

App.java
package com.sample.app;

public class App {

 public static void main(String args[]) {

  String hexaString = "ff";
  int number = Integer.parseInt(hexaString, 16);

  System.out.println("hexaString : " + hexaString);
  System.out.println("number : " + number);

 }

}

Output
hexaString : ff

number : 255


You may like

No comments:

Post a Comment