- 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
Java Program to retrieve the current bits in a byte array in two’s-complement form
Use the toByteArray() method to return a byte array containing the two's-complement representation of this BigInteger. The byte array will be in big-endian byte-order: the most significant byte is in the zeroth element.
The following is an example to retrieve the current bits in a byte array in two’s-complement form.
Example
import java.math.*; public class Demo { public static void main(String[] args) { // BigInteger objects BigInteger bi1, bi2; byte b1[] = { 0x1, 0x00, 0x00 }; bi1 = new BigInteger(b1); b1 = bi1.toByteArray(); String strResult = "Byte array representation of " + bi1 + " = "; System.out.println(strResult); for (int i = 0; i < b1.length; i++) { System.out.format("0x%02X
", b1[i]); } } }
Output
Byte array representation of 65536 = 0x01 0x00 0x00
Advertisements