- 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
Advertisements