- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Get byte array from BigInteger in Java
First, set the BigInteger object with binary.
BigInteger val = new BigInteger("100000000110001100000", 2);
Now, use the toByteArray() method.
byte[] byteArr = val.toByteArray();
The following is an example −
Example
import java.math.BigInteger; public class Demo { public static void main(String[] argv) throws Exception { BigInteger val = new BigInteger("100000000110001100000", 2); byte[] byteArr = val.toByteArray(); for (int i = 0; i < byteArr.length; i++) { System.out.format("0x%02X
", byteArr[i]); } } }
Output
0x10 0x0C 0x60
- Related Articles
- Create BigInteger from byte array in Java
- Subtract one BigInteger from another BigInteger in Java
- Divide one BigInteger from another BigInteger in Java
- How to get the Checksum of a Byte Array in Java?
- Sort Byte Array in Java
- Filling byte array in Java
- Java Program to create Stream from a String/Byte Array
- How to concatenate byte array in java?
- Multiply one BigInteger to another BigInteger in Java
- Convert byte Array to Hex String in Java
- Convert Hex String to byte Array in Java
- How to print a byte array in Java?
- Java Program to get the prime numbers with BigInteger type
- Java Program to fill elements in a byte array
- How to convert BLOB to Byte Array in java?

Advertisements