0

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
2
Contributors
3
Replies
12
Views
1 Year
Discussion Span
Last Post by JamesCherrill
0

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.

Edited by JamesCherrill

0

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

0

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.

Edited by JamesCherrill

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.