In this tutorial, we will see “How to convert Decimal to Hexadecimal in Java?”
How to convert decimal number to hexadecimal in java
Java – How to convert Decimal number to Hexa-Decimal? Click To Tweet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | /** * Using Java, Convert Decimal Number to Hexadecimal * @author Deepak Verma * */ import java.util.Scanner; public class Convert_Decimal_Number_To_Hexadecimal_Java_Example { public static void main(String[] args) { try (Scanner sc = new Scanner(System.in)) { System.out.print("Enter a Decimal Number: "); int decimalNumber = sc.nextInt(); String hexadecimalNumber = Integer.toHexString(decimalNumber); System.out.println("Hexa-decimal representation of " + decimalNumber + " is: " + hexadecimalNumber); } } } |
Output:
1 2 | Enter a decimal number: 23 Hexadecimal representation of 23 is: 17 |
How to convert decimal number to hexadecimal in java
In the above example, It uses Integer.toHexString()
method, which is a built-in method in Java to convert decimal number to a hexadecimal counterpart.
Java – How to convert Decimal number to Hexa-Decimal? Click To Tweet
Do you like this Post? – then check my other helpful posts:
- Convert a Stream to a List in Java 8
- Stream maptoint in Java 8 with examples
- Double the numbers of specified ArrayList using Streams
- Double the even / odd numbers of a specified ArrayList using Streams
- How to check if Number is Prime or not using Streams
- Retrieve Even/Odd Numbers within the Range using Java 8 Streams
- How to add/sum up the ArrayList integers using Java8 Streams
- Generate Prime Numbers in Java 8 using Streams
- Comparator example – Collections sort with/without Lambda in Java 8
- How to pass function as a parameter in a method in Java 8?
- Remove duplicates from ArrayList in Java 8
- ForEach examples for Map/List in Java 8
Other Useful References: