How to transform a byte array into two short arrays

Djembefola

Active Member
Licensed User
Longtime User
I have a byte array with the following structure:

First frame: Byte1,Byte2,Byte3,Byte4
Next frame: Byte1,Byte2,Byte3,Byte4
...
Last frame: Byte1,Byte2,Byte3,Byte4

The bytes are "Little Endian".

What i need to do, is:
transform byte1 and byte2 of each frame into a short in shortarray1.
transform byte3 and byte4 of each frame into a short in shortarray2.

How can i do this?
 

thedesolatesoul

Expert
Licensed User
Longtime User
Here:
B4X:
Dim sample1(ReadBufferSize/2) As Short 
Dim sample2(ReadBufferSize/2) As Short 
Dim bs1(ReadBufferSize) As Byte 
Dim bs2(ReadBufferSize) As Byte 
   
fin1.ReadBytes(bs1,0,bs1.Length)
fin2.ReadBytes(bs2,0,bs2.Length)
      
Dim BC As ByteConverter 
      
BC.LittleEndian = True
sample1 = BC.ShortsFromBytes(bs1)
sample2 = BC.ShortsFromBytes(bs2)
 
Upvote 0
Top