Android Question AStream_NewData Byte in Int

Discussion in 'Android Questions' started by red30, Mar 14, 2019.

  1. red30

    red30 Active Member Licensed User

    Code:
    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: Mar 14, 2019
  2. DonManfred

    DonManfred Expert Licensed User

    B4A is using Signed bytes (-127 to 127)
    Convert the bytes to unsigned....

    Code:
    Sub ToUnsigned(b As Byte) As Int
       
    Return Bit.And(0xFF, b)
    End Sub
    Code:
    New123(j)=ToUnsigned(Buffer(i))
     
    Erel, red30 and thetahsk like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice