Android Question AStream_NewData Byte in Int

red30

Well-Known Member
Licensed User
Longtime User
B4X:
Sub AStream_NewData (Buffer() As Byte)
  
    For i = 0 To Buffer.Length-1
        New123(j)=Buffer(i)
        j=j+1
        If j = 2 Then
            j=0
            Sig=Bit.Or(Bit.ShiftLeft(New123(1),8),New123(0))
            Graf
        End If
    Next
End Sub
I send from the microtrollet an array of values 1,2,3,4 ... 4095. And I get: 1,2,3...125,126,127,-128,-127,-126...-3,-2,-1,256,257,258...381,382,383,-128,-127,-126...-3,-2,-1,512,513,514 and so on! I can not understand why this is happening? How to fix it? With sending, everything is fine, I checked 0 ... 4095 several times.
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
B4A is using Signed bytes (-127 to 127)
Convert the bytes to unsigned....

B4X:
Sub ToUnsigned(b As Byte) As Int
   Return Bit.And(0xFF, b)
End Sub

B4X:
New123(j)=ToUnsigned(Buffer(i))
 
Upvote 0
Top