Hi guys,

I've been using BluetoothLE extension to communicate with my device through BLE1.

I successfully receive and send data without problem.

Now I am stuck trying to find a way to convert my data into number

My device sends a string of data like this {152, 55, 48, 48, 70, 47}

If I receive as StringValue, it will be "(?700F/)" . '?' is unknow character not a question mark.

If I receive as BytesValue, it will be "(152 55 48 48 70 47)" also as a string.

The first byte defines what kind of message it is, the next 4 bytes is 16 bit number formatted in HEX.

If receiving as StringValue, I cannot compare that single character with a decimal value.

Those conditions never true.

If receiving as BytesValue, ie. "152".

The condition does work, but I am stuck at converting the rest to a 16 bit number. I cannot find a way to do this.

If it is in C, I can write a function to do so in less than 5 minutes without using any library.

```
uint16_t uchar_to_uint16(const uint8_t* in_uchar)
{
uint8_t b0 = in_uchar[0], b1 = in_uchar[1], b2 = in_uchar[2], b3 = in_uchar[3];
if (b0 >=48 && b0 <=57) b0 -= 48; // 0 -- 9
if (b0 >=65 && b0 <=70) b0 -= -55; // A -- F, or b0 = b0 -65 +10
if (b1 >=48 && b1 <=57) b1 -= 48; // 0 -- 9
if (b1 >=65 && b1 <=70) b1 -= -55; // A -- F, or b0 = b0 -65 +10
if (b2 >=48 && b2 <=57) b2 -= 48; // 0 -- 9
if (b2 >=65 && b2 <=70) b2 -= -55; // A -- F, or b0 = b0 -65 +10
if (b3 >=48 && b3 <=57) b3 -= 48; // 0 -- 9
if (b3 >=65 && b3 <=70) b3 -= -55; // A -- F, or b0 = b0 -65 +10
if (b0>15 || b1>15 || b2>15 || b3>15) return 0; // fail to convert, return 0;
return (uint16_t) (b0) | (b1<<3) | (b2<<7) | (b3<<11);
}
```

But I am unable to do this using language blocks.

Could someone shed some light on this for me?

Thanks

Edit:

I've tried this procedure to convert from ascii to decimal value https://gallery.appinventor.mit.edu/?galleryid=6407304567324672

But it just return 0 instead of 152.