Android Question Little Endian to Big Endian

walterf25

Expert
Licensed User
Longtime User
Hi everyone, I am currently working on an b4x app which receives and sends data over a BLE device, I am a little confused with Little Endianess, according to the engineers who are writing the firmware for the BLE side of this product, the byte order they are using to send data over to the app is Little Endian.

My question is, if I receive some data like this:

A60E340DDC0F200392FF26070607DC053200
which converted to bytes should be this:

-90
14
52
13
-36
15
32
3
-110
-1
38
7
6
7
-36
5
50
0

How can I turn this data into either a hex string or byte array in big engian byte order.

The engineers have sent me this which represents the data they are sending

littleendian.jpg


So in order for me to be able to extract the data and interpret it on my app, the data should look like this
003205DC07060726FF9203200FDC0D340EA6

I have seen the byteconverter library which has a LittleEndian property, but setting it to True does not seem to work, also I have looked into the RandomAccessFile which a parameter in the Iniatilize2 and initialize3 method, but setting this to True also doesn't not seem to make any difference, any thoughts or ideas?

Thanks All.

Walter
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub AppStart (Args() As String)
    Dim s As String = "A60E340DDC0F200392FF26070607DC053200"
    Dim bc As ByteConverter
    bc.LittleEndian = True
    Dim shorts() As Short = bc.ShortsFromBytes(bc.HexToBytes(s))
    For Each shr As Short  In shorts
        Log(shr)
    Next
End Sub

Waiting for debugger to connect...
Program started.
3750
3380
4060
800
-110
1830
1798
1500
50
 
Upvote 1
Top