Convert Bytes to bits

dedalo picture dedalo · Jun 3, 2009 · Viewed 13k times · Source

I'm working with java.

I have a byte array (8 bits in each position of the array) and what I need to do is to put together 2 of the values of the array and get a value.

I'll try to explain myself better; I'm extracting audio data from a audio file. This data is stored in a byte array. Each audio sample has a size of 16 bits. If the array is:

byte[] audioData;

What I need is to get 1 value from samples audioData[0] and audioData[1] in order to get 1 audio sample.

Can anyone explain me how to do this?

Thanks in advance.

Answer

Adam Robinson picture Adam Robinson · Jun 3, 2009

I'm not a Java developer so this could be completely off-base, but have you considered using a ByteBuffer?