Sunday 26 May 2019

Java: Convert integer to hexa string


'Integer.toHexString' method converts an integer to hexa string.

Example
int i = 255;
String hexaString = Integer.toHexString(i);

App.java
package com.sample.app;

public class App {

 public static void main(String args[]) {
  int i = 255;
  String hexaString = Integer.toHexString(i);

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

 }

}

Output
i : 255
hexaString : ff


You may like

No comments:

Post a Comment