English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Parse and Format as Hexadecimal in Java

To parse and format as hexadecimal in Java, we use the BigInteger class. The java.math.BigInteger class provides equivalents for all primitive integer operators in Java and all related methods in java.lang.Math.

In the following example, we use BigInteger to create an object. In this way, we set some values as hexadecimal and radix in the parameters, that is, hexadecimal as16.

BigInteger bi = new BigInteger("2ef 16);

Let's look at 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 Result

2ef