spaceman
spaceman

Reputation: 649

How to convert HEX to human readable

I'm trying to convert from a HEX to ASCII and I'm getting this message. I would like to understand how to interpret it in the correct way.

0x2b6162630704fe17

Using the npm module hex2ascii it returns this:

"+abc\u0007\u0004þ\u0017"

if I convert from an online converter, it returns :

+abcþ

Could someone help me to interpret this? I am using node.

Am I doing something wrong?

Appreciate the help!

Upvotes: 0

Views: 1415

Answers (2)

Moritz Roessler
Moritz Roessler

Reputation: 8611

If you look at the string in the console, you will notice that the two strings you're posted are actually the same.

The gist is, the string contains nonprintable unicode characters, which get escaped by the hex2ascii module.

The online converter you are using tries to display those characters. Since they are not printable you simply cannot see them.

Let's convert the hex string

var conv = "2b6162630704fe17".match (/(..)/g).reduce ((a,c) => a + String.fromCharCode(parseInt (c,16)), "") 
conv //"+abcþ"

It looks just like the String from the converter! Let's compare it to the other string

conv === "+abc\u0007\u0004þ\u0017" // true

Upvotes: 1

Ctznkane525
Ctznkane525

Reputation: 7465

Are you sure its 8 digit ASCII?

If it is, each 2 hex characters represents a given ASCII number.

So: 2b6162630704fe17

  • First 2b, which is 2 * 16 + 11 = 43 - which is a plus sign
  • 61, which is 6 * 16 + 1 = 97 = lowercase a
  • 62, which is 6 * 16 + 2 = 98 = lowercase b
  • 63, which is 6 * 16 + 3 = 99 = lowercase c
  • 07, which is 0 * 16 + 7 = 7 = that's a special unprintable character.

references to convert the numbers to characters - asciitable.com

Based on the 07, I wonder if your data is truly ascii, or a different encoding.

Upvotes: 0

Related Questions