Java BigInteger toByteArray() method

The toByteArray() method of Java BigInteger class is used to find the binary representation of this BigInteger in the form of byte array. A byte array contains the minimum number of bytes required to represent this BigInteger, including at least one sign bit, which is (ceil((this.bitLength() + 1)/8)).

Syntax:

Parameter:

NA

Returns:

This method returns a byte array containing the 2's complement representation of this BigInteger.

Exception:

NA

Note: The byte array will be in big-endian byte-order: the most significant byte is present as the 0th element. For example: 0x10,0x14 etc.

Example 1

Test it Now

Output:

Byte array representation of 20 is: 0x14

Example 2

Test it Now

Output:

Byte array representation of 255 is: 0x00 0xFF

Example 3

Test it Now

Output:

Byte array representation of 65535 is: 0x00 0xFF 0xFF

Next TopicJava BigInteger




Latest Courses