Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to convert Decimal to Hexadecimal in Java
To convert decimal to hexadecimal, use any of the two methods i.e.
Integer.toHexString() − It returns a string representation of the integer argument as an unsigned integer in base 16.
Integer.parseInt() − It allows you to set the radix as well, for example, for hexadecimal set it as 16.
Let us see an example now to convert decimal to hexadecimal using Integer.toHexString() method.
Example
public class Demo {
public static void main( String args[] ) {
int dec = 158;
System.out.println(Integer.toHexString(dec));
}
}
Output
9e
Let us see an example now to convert decimal to hexadecimal using Integer.parseInt() method.
Example
public class Demo {
public static void main( String args[] ) {
String str = "3d8";
System.out.println(Integer.parseInt(str, 16));
}
}
Output
984
Advertisements
