0

maybe this is a noob question, but I'm receiving some data over TCP and when I look at the string I get the following:

\x00\r\xeb\x00\x00\x00\x00\x01t\x00

What is that \r character, and what does the t in \x01t mean?

I've tried Googling, but I'm not sure what to Google for...

thanks.

4
  • 2
    Doesn't look much like any encoding I can think of (four NULL bytes in a row?). Looks more like binary data, I'd say... Commented Oct 11, 2010 at 14:06
  • It is a response I get from a traffic simulator with a TCP server, and I have to parse it myself based on the length(1st byte) and the command(2nd byte), so how do I interpret the r and the t? Commented Oct 11, 2010 at 14:10
  • 2
    In hex, this is 00 0d eb 00 00 00 00 01 74 00. \r, carriage return, is the same as 0x0d and the letter t corresponds to 0x74. Commented Oct 11, 2010 at 14:19
  • -1: Don't ask us. Who is sending the data? Ask them. They actually know what data they're sending. Commented Oct 11, 2010 at 20:12

3 Answers 3

9

\r is a carriage return (0x0d), the t is a t.

Sign up to request clarification or add additional context in comments.

3 Comments

If that's the case, why isn't it given simply as 0x0d?
Because there's a standard escape, \r, designated for it. Search for "C character escapes" and you'll find a table of how they're represented.
@nieldw Python represents bytes objects as strings of hex values identifying each byte, except when the hex value is that of a printable/commonly used ASCII value.
4

Viewing binary data in strings can sometimes be confusing, especially if they're long, but you can always convert it to some easier-to-read hex.

>>> data = '\x00\r\xeb\x00\x00\x00\x00\x01t\x00'
>>> ' '.join(["%02X" % ord(char) for char in data])
'00 0D EB 00 00 00 00 01 74 00'

Also, if you're just parsing the byte string into fields, just ignore the string and just go right to unpacking it with the struct module:

>>> import struct
>>> length, command, eggs, spam = struct.unpack('!BBi4s',data)
>>> #...whatever your fields really are
>>> print "len: %i\ncmd: %i\negg qty: %i\nspam flavor: '%s'" % (
...     length, command, eggs, spam)
len: 0
cmd: 13
egg qty: -352321536
spam flavor: ' ☺t '

Comments

2

When displaying data as a string, printable characters (such as 't' are displayed as characters, known control sequences are displayed as escapes, and other bytes are displayed in \x## form. Example:

>>> s='\x74\x0d\x99'
>>> s
't\r\x99'

You can dump a hexadecimal form with:

>>> import binascii
>>> binascii.hexlify(s)
'740d99'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.