B4R Code Snippet B4R Ints to B4A and B4J Ints

I forgot that B4R ints are 2 bytes and B4A/J ints are 4 Bytes.
Hopefully this assists someone else!

So B4R side

B4X:
Dim SendArray() As Int
' Populate the array
Sub SendIntsB4r
        astream.Write(bc.IntsToBytes(SendArray))
End Sub


B4A/J Side
B4X:
Sub AStream_NewData (Buffer() As Byte)
    ' Converts buffer with 2 bytes per int from B4R to B4A or B4J Int with 4 bytes per int
    Dim Data(Buffer.length) As Int    ' could be /2
    Dim j As Int =0
    For i=0 To Buffer.Length-1 Step 2
        bc.LittleEndian = True
        Data(j) = bc.IntsFromBytes(Array As Byte(Buffer(i),Buffer(i+1),0,0))(0)     ' first, second, third and fourth byte
    j=j+1
    Next
    Log("Data(0) & "  "& Data(1) &"  " & Data(2) & "  " & Data(3)&"  "& Data(4)&"  "& Data(5)&"  "& Data(6))
End Sub
 
Top