Java Program to convert integer to hexadecimal

Java 8Object Oriented ProgrammingProgramming

Use the + Integer.toHexString() method in Java to convert integer to hexadecimal.

Let’s say the following is our integer.

int val = 768;

Let us convert it to a hexadecimal value.

Integer.toHexString(val)

The following is the final example with the output.

Example

 Live Demo

public class Demo {
    public static void main(String[] args) {
       int val = 768;
       // integer
       System.out.println("Integer: "+val);
       // hex
       System.out.println("Hex String = " + Integer.toHexString(val));
    }
}

Output

Integer: 768
Hex String = 300
raja
Published on 12-Dec-2018 06:50:02
Advertisements