@Chris Mower The result depends on the byte-ordering but it seems easy in your case because &h70EF = 28911
The easiest way to convert really depends on the format of your data at first. Here, I will consider that you got a string (“70EF BFBD 70EF 70DD 71BE 69AA 71AE”) and want to get the values out of it.
[code]dim values() as string = Split( “70EF BFBD 70EF 70DD 71BE 69AA 71AE”, " " ) //Split all the 16-bit values
for each s as string in values //Parse the 16-bit values
dim numValue as integer = Val( “&h” + s ) // Evaluate each string value prepended with “&h”
//>>>> Do something with the numerical value
sorry but there is still a misundersatnding. The data that comes back is not ASCII as such but raw binary. It comprises the byte values 70EFBFBD70EF70DD71BE69AA71AE and not the ascii characters “70EFBFBD70EF70DD71BE69AA71AE”
Therefore I need to extract the first four bytes, 70EF and convert that to the UInt16 value 28911, then the next four values BFBD and convert that to 49085 and so on to the end of the input data. I haven’t been able to find a way to do that in Xojo but as I am new to it I may be missing something.
@Chris Mower Then you can also use a MemoryBlock to handle the resulting “String” (aka suite of bytes) as a MemoryBlock and a String are interchangeable !
dim mb as MemoryBlock = myResultAsString
Aha, that looks like what I am needing. Let me give it a try.
thanks for that it works exactly as I need. This gives me the conversion to a double array
Dim LoopCount As Int16
Dim mb As New MemoryBlock( 4096 )
Dim db As Double
mb = InputData
If x = ( 2 * DataCount ) Then
For LoopCount = 0 To x - 1 Step 2
db = mb.UInt16Value( LoopCount )
data.Append( db )
Many thanks for the help