1

recently I was trying to send a .bin file to BLE peripheral device and it ended up in unexpected result.

While debugging I could see iOS's byteArray(.bin -> Data -> byteArray) content is different from Android's byteArray. Can anyone help me understand why is it like this?

Sample data reference: (First few bytes of byteArray on each platform)
iOS: [233, 6, 2, 79, 176, 82, 8, 64, 238, 0]
Android: [-23, 6, 2, 79, -80, 82, 8, 64, -18, 0]

Note* In both platform the file size is same.

Bharath
  • 2,064
  • 1
  • 14
  • 39
  • Please use hexadecimal notation for the byte values – blackapps Sep 27 '21 at 20:55
  • Thank you @blackapps, tried it but after converting the result was [101, 57, 48, 54, 48, 50, 52, 102, 98, 48]. I'll try few more approaches and will post on success. – Bharath Sep 27 '21 at 21:12
  • 4
    Android is showing you Int8 while ios is showing you Uint8. This doesn't affect the actual bits, just how they are represented when you print them – Paulw11 Sep 27 '21 at 21:17
  • 1
    You are getting the 2's complement on Android of the equivilent on iOS for each value that doesn't match - because of reason outlined by @Paulw11 – Mark Sep 27 '21 at 21:21
  • Yes @Paulw11, you are right. But as far as we came to this is the level it leaves us the only difference is these byte values. So need to figure out the right conversion to make it right. Else I guess firmware should be handling these byte changes since that's the default in iOS platform. – Bharath Sep 27 '21 at 21:22
  • Yes, but there isn't any difference in the byte values. Just how they are being interpreted when you print them. If you send the binary data over BLE it shouldn't matter. If you are converging the bytes to a string representation, then it will, because you want unsigned, not signed. If you are sending a string then you should send hex not decimal representation – Paulw11 Sep 27 '21 at 21:29
  • Thank you all :-) This conversation helped in learning few information. Now with a bit of code `data.map{Int8(bitPattern: $0)}` @Paulw11 tried to check with Signed & UnSigned and I had found matching values like Android. – Bharath Sep 27 '21 at 21:29
  • 1
    No, you want Android to use Uint8, not the other way around. UInt8 is correct for binary data, Int8 is not – Paulw11 Sep 27 '21 at 21:31
  • Sure @Paulw11, I'll suggest our hardware team to handle it accordingly and Android team to switch to the right way. – Bharath Sep 27 '21 at 21:32
  • `but after converting the result was [101, 57, 48, .....` Impossible. Wrong conversion. 101 is no hexadecimal value. Please try again. – blackapps Sep 27 '21 at 21:47
  • `I'll suggest our hardware team to handle it accordingly and Android team to switch to the right way` What a fuss. You dont have to do anything. The files are the same. The only thing you should not do is print them in decimal notation. Be it signed or unsigned. Just print hexadecimal and see that all bits are equal. – blackapps Sep 27 '21 at 21:49
  • Got it @blackapps, irrespective of the print value the data would be same on hexadecimal representation. Actually this question was raised since I was facing this main issue https://stackoverflow.com/questions/69338662/uploading-firmware-via-bluetooth-is-not-working-in-ios?noredirect=1#comment122580566_69338662 – Bharath Sep 27 '21 at 22:42

0 Answers0