- 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
- Related Articles
- Java Program to fill elements in a byte array
- Java Program to compare two Byte Arrays
- Java Program to convert byte[] array to String
- Java Program to convert String to byte array
- How to print a byte array in Java?
- Java Program to create Stream from a String/Byte Array
- Java program to convert Byte array to IP Address
- Sort Byte Array in Java
- Filling byte array in Java
- How to concatenate byte array in java?
- Java Program to shift bits in a BigInteger
- How to get the Checksum of a Byte Array in Java?
- How to convert a PDF to byte array in Java?
- Java Program to return the hexadecimal value of the supplied byte array
- Convert byte Array to Hex String in Java

Advertisements