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
Parse and format to hexadecimal in Java
To parse and format to hexadecimal in Java, we have used the BigInteger class. The java.math.BigInteger class provides operations analogues to all of Java's primitive integer operators and for all relevant methods from java.lang.Math.
In the below example, we have taken BigInteger and created an object. With that, some values have been set by us in the arguments as the hexadecimal and the radix i.e. 16 for hexadecimal.
BigInteger bi = new BigInteger("2ef", 16);
Let us see an example.
Example
import java.math.*;
public class Demo {
public static void main( String args[] ) {
BigInteger bi = new BigInteger("2ef", 16);
String s = bi.toString(16);
System.out.println(s);
}
}
Output
2ef
Advertisements
