I am able to read 4byte data using byteBuf.getInt() and same way till 8 bytes I am using getLong.

I am not able to read 16 byte data. when I googled I understand that java BigDecimal will support 16 byte data.

Could any one please help on reading 16 byte data from ByteBuffer?

I am not sure how to proceed further.

                byte[] decimalBuffer = new byte[16];
                in.read(decimalBuffer);
                ByteBuffer decimalByteBuffer = ByteBuffer.wrap(decimalBuf);
                //Need statements to read 16 byte data from ByteBuffer

Recommended Answers

All 3 Replies

16 bytes is 16 bytes. How you read them depends on what they represent and what you want to do with them. What are these bytes? Are they a signed, big-endian 16 byte integer value, or what? Knowing where they come from may help.

these are binary representation of decimal values which will be in decimalBuffer. and it will be in Little Endian format.

Then maybe you could try reading the 16 bytes one at at time and storing them in reverse order into byte[16] array, then use that for the BigInteger constructor call?

public BigInteger(byte[] val)
Translates a byte array containing the two's-complement binary representation of a BigInteger into a BigInteger. The input array is assumed to be in big-endian byte-order: the most significant byte is in the zeroth element.
Parameters:
val - big-endian two's-complement binary representation of BigInteger.
Throws:
NumberFormatException - val is zero bytes long.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.