Sunday, 5 January 2020

How to print integer in hex format?

‘Integer.toHexString’ method is used to convert an integer to hex string.

Example
int i = 1027;
String hexString = Integer.toHexString(i);

App.java
package com.sample.app;

public class App {

 public static void main(String args[]) {
  int i = 1027;

  String hexString = Integer.toHexString(i);
  
  System.out.println("Hexa form of " + i + " is " + hexString);

 }
}

Output
Hexa form of 1027 is 403

You may like

No comments:

Post a Comment