views:

705

answers:

3

I'm attempting to decode text which is prefixing certain 'special characters' with \x. I've worked out the following mappings by hand:

\x28   (
\x29   )
\x3a   :

e.g. 12\x3a39\x3a03 AM

Does anyone recognise what this encoding is?

+1  A: 

It's ASCII. All occurrences of the four characters \xST are converted to 1 character, whose ASCII code is ST (in hexadecimal), where S and T are any of 0123456789abcdefABCDEF.

pts
You can easily decode this type of text by just putting it into quotes in an interactive Python interpreter.
Paul Fisher
+1  A: 

The '\xAB' notation is used in C, C++, Perl, and other languages taking a cue from C, as a way of expressing hexadecimal character codes in the middle of a string.

The notation '\007' means use octal for the character code, when there are digits after the backslash.

In C99, you can also use \uabcd and \U00abcdef to encode Unicode characters in hexadecimal.

Jonathan Leffler
A: 

I'm guessing that what you are dealing with is a unicode string that has been encoded differently than the output stream it was sent to. ie. a utf-16 string output to a latin-1 device. In that situation, certain characters will be outputted as escape values to avoid sending control characters or wrong characters to the output device. This happens in python at least.

lostlogic