Android Question Byte conversion

JTmartins

Active Member
Licensed User
Longtime User
Although a short may not be exactly the same as a Uint16, I believe it may serve your purposes.

You will need to use Byteconverter library, and something like this :

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Private a(2) As Byte
    Private result() As Short
    a(0)=0x12
    a(1)=0x08
    result=ConvertShort(a)
End Sub

Sub ConvertShort (barray() As Byte) As Short()
    Private bc As ByteConverter
    Private shorts() As Short
    shorts=bc.ShortsFromBytes(barray)
    Return shorts
End Sub

in the end, the result array[0] will hold the value you want.
 
Upvote 0
Top