String encoding question

What is the encoding of this string?

\x48\x65\x6C\x6C\x6F\x20

P.S. I found it in some Javascript source.

Upvotes: 2

Views: 1514

Answers (3)

wsanville
wsanville

Reputation: 37506

That's hexadecimal for the string Hello.

Upvotes: 1

Paul
Paul

Reputation: 141829

That is Hexadecimal for "Hello "

  • 'H' is 48
  • 'e' is 65
  • 'l' is 6C
  • 'o' is 6F

20 is a space

Here is a list of ascii codes: http://www.asciitable.com/

The \x is just telling something that it is hexadecimal. In a Javascript string it will \x48 will represent a single character ('H'). x is commonly used to mean hex.

For example, since 48 is Hexadecimal for the decimal number 72, the javascript statement:

0x48 === 72 is true

You can convert from Hex to ascii in javascript with String.fromCharCode(0x48).

You can convert from hexadecimal to decimal with parseInt('0x48')

Upvotes: 4

templatetypedef
templatetypedef

Reputation: 372674

Each of the values of the form \xNN are hexadecimal literal values. They map to ASCII values encoding particular characters. If you go to a JavaScript console (for example, the one in the Chrome browser I'm using now) and enter

alert("\x48\x65\x6C\x6C\x6F\x20");

You'll get a popup that says

Hello

Since the ASCII values for the letters H, e, l, and o are 0x48, 0x65, 0x6C, and 0x6F, respectively. The final 0x20 encodes a space character, which does not display anywhere.

For more information about the ASCII table for encoding character values, see this website containing the complete table.

My question is why on earth any site would do this. It's less space-efficient in terms of number of source characters than just writing out Hello!

Upvotes: 1

Related Questions