0

Just trying to line these up in a long string. All works well but for some reason interprets \x2b as a + sign?

I have a feeling I am misinterpreting bytes...any instruction welcome!

>>> a = b'\x02'
>>> b = b'\xca'
>>> c = b'\x2b'
>>> d = b'\x87'
>>> print(a+b+c+d)
b'\x02\xca+\x87

Thanks, Matt

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
Matt
  • 57
  • 4
  • 1
    That's because `\x2b` == `+`. – Martijn Pieters Aug 09 '17 at 13:09
  • The `+` is simply the ascii equivalent of `\x2b`. In order to make binary strings short, Python replaces bytes that have an ASCII equivalent, with that ASCII char. – Willem Van Onsem Aug 09 '17 at 13:09
  • From the duplicate: *bytes objects basically contain a sequence of integers in the range 0-255, but when represented, Python displays these bytes as ASCII codepoints to make it easier to read their contents. Any bytes outside the printable range of ASCII characters are shown as escape sequences (e.g. `\n`, `\x82`, etc.).* – Martijn Pieters Aug 09 '17 at 13:11

0 Answers0