Convert number into byte array?

Hi

I am doing some BLE comms and I have it nearly working except for one problem…

I can transfer a data structure (mix of number and strings) received into BluetoothLE.BytesReceived fine. For instance, 10 bytes might comprise an uint32 integer (first 4 bytes), a boolean (1 byte) and a string (5 characters long).

To convert the appropriate byte values to an integer I pass in the following…

image

…to this function…

image

My problem arises when I want to send a similar structure back from the App. I can send an array of bytes by building a list with AppendToList blocks and sending it using BluetoothLE.WriteBytes. But How do I take a number and convert it to 4 bytes? The reverse of the CLongInt function written above. It will be something like this (Xojo)…

Dim b0 As Byte = i And &h000000FF
Dim b1 As Byte = Bitwise.ShiftRight(i And &h0000FF00, 8, 32)
Dim b2 As Byte = Bitwise.ShiftRight(i And &h00FF0000, 16, 32)
Dim b3 As Byte = Bitwise.ShiftRight(i And &hFF000000, 24, 32)

…could anyone provide a few pointers?

Thanks

In case anyone else needs this I think the following is working…
image

1 Like