- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert BigInteger into another radix number in Java
First, create a BigInteger.
BigInteger val = new BigInteger("198");
Let us convert it to Binary, with radix as 2.
val.toString(2);
Convert it to Octal, with radix as 8.
val.toString(8);
Convert it to HexaDecimal, with radix as 16.
val.toString(16);
The following is an example −
Example
import java.math.BigInteger; public class Main { public static void main(String[] args) { BigInteger val = new BigInteger("198"); System.out.println("Value: " + val); // binary System.out.println("Converted to Binary: " + val.toString(2)); // octal System.out.println("Converted to Octal: " + val.toString(8)); // hexadecimal System.out.println("Converted to Hexadecimal: " + val.toString(16)); } }
Output
Value: 198 Converted to Binary: 11000110 Converted to Octal: 306 Converted to Hexadecimal: c6
- Related Articles
- Multiply one BigInteger to another BigInteger in Java
- Subtract one BigInteger from another BigInteger in Java
- Divide one BigInteger from another BigInteger in Java
- Java Program for Radix Sort
- Negate a BigInteger in Java
- BigInteger class in Java\n
- Convert Short into String in Java
- Create BigInteger via string in Java
- Working with BigInteger Values in Java
- Math Operations on BigInteger in Java
- Insert a String into another String in Java
- Shift left in a BigInteger in Java
- Shift right in a BigInteger in Java
- Set a bit for BigInteger in Java
- Create BigInteger from byte array in Java

Advertisements