Java Program to convert integer to hexadecimal


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

Updated on: 26-Jun-2020

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements