0

I used android to parse a long variable into 6 bytes, which is received by python code through bluetooth on my computer to put it together. On the android side, it shows that it sends 6 bytes.

If the byte array sent from android for example is "F�I��", python print received byte array is exactly the same "F�I��". But len(data) = 12, not 6. It looks like each "�" has a length of 3. Anyone have a clue? How do I interpret it correctly?

Thanks!

XWen
  • 361
  • 1
  • 2
  • 10
  • Which version of python are you using? Python 2 and 3 handle bytestrings very differently. Can you share the code? – Rafael Barros Jun 17 '14 at 14:55
  • I use 2.7. Below is the code. Also I found that each "�" is a negative byte, probably something to do with that. I'm digging into it. { print("received [%s]" % data) # print: F�I�� print len(data) # print: 12 l = 0 for i in range(len(data)): print ord(data[i]) l = l<<8 l = l + ord(rawdata[i]) print l } – XWen Jun 17 '14 at 15:19
  • Are you receiving the data with a python socket? This looks like encoding problem, see if this makes sense to you: http://stackoverflow.com/questions/5901706/the-bytes-type-in-python-2-7-and-pep-358 – Rafael Barros Jun 17 '14 at 15:27
  • @RafaelBarros Thanks for the hint. Just found that it's the java problem on the android side. The weird length change happened when I convert a byte array to a String. – XWen Jun 17 '14 at 15:47

0 Answers0