iOS Question Hex to Byte conversion 2 Bytes only want 1

SFE

Member
Licensed User
Hello

I know for most of you this is probably pretty basic but here we go. I am sending data via the BLE link. As part of my data I need to send a hex 0x0d (carriage return). I want to send 1 hex byte "0d".

This is what i presently have. This generates 2 bytes "00" or Null and "0d". What would be the method to get DataTX2 down to 1 byte.
if I change the hex value to 0xd then the code crashes on the conversion line.

Any suggestions would be greatly appreciated.

Dim DataTx2() As Byte
DataTx2= ByteConv.HexToBytes("0x0d")
manager.WriteData(AirConsoleDataService,AirConsoleDataChara,DataTx2)

Thanks
 

emexes

Expert
Licensed User
Does this do the job? :

B4X:
Dim DataTx2(1) As Byte
DataTx2(0) = 0x0d
manager.WriteData(AirConsoleDataService, AirConsoleDataChara, DataTx2)

or maybe even this:

B4X:
manager.WriteData(AirConsoleDataService, AirConsoleDataChara, Array As Byte(0x0d))    'send carriage return ie ASCII 0x0d
 
Upvote 0

emexes

Expert
Licensed User
I think this would have worked:

DataTx2 = ByteConv.HexToBytes("0x0d")

except that HexToBytes doesn't need - or expect - the 0x prefix because the number base is implied by the function name already.

A similar function is:

DataTx2 = Bit.ParseInt("0d", 16)
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
the Array as Byte performed as expected.

You're probably already onto this but just in case:

the Array literal construct can also handle multiple values eg:

DIm Hello() As Byte = Array As Byte(72, 101, 108, 108, 111, 33)
 
Upvote 0
Top