What's a Hex Dump - What does it mean?
Asked Answered
H

2

5
thegladiator:~/cp$ cat new.txt
Hello World This is a Trest Progyy

thegladiator:~/cp$ hexdump new.txt
0000000 6548 6c6c 206f 6f57 6c72 2064 6854 7369
0000010 6920 2073 2061 7254 7365 2074 7250 676f
0000020 7979 000a                              
0000023

How is that text data represented in hex like that? What is the meaning of this?

Helio answered 6/4, 2011 at 19:48 Comment(8)
This didn't help? en.wikipedia.org/wiki/Hex_dumpAnnuitant
What OS? (that might help with why the bytes are swapped)Pasteurization
@S. Lott: That sounds very close to a LMGTFY answer. meta.stackexchange.com/questions/15650/…Burkle
Ubuntu / Linux . Wiki didnt help me grasp the concepts as much as I wanted . Why H is 48 ? ASCII ?Helio
@Nishant: Yes, 48 is ASCII for H. However for some reason your bytes are swapped as KevinDTimm points out. Don't know why that's happening.Burkle
H is 48 hex (do a man ascii to see why)Pasteurization
What about the first 0000000 0000010 etc data ?Helio
@Nishant: Those are the byte offsets in your file. The first row shows the first 16 bytes, the second row shows the second 16 bytes, etc.Burkle
P
9

it's just what it says, a dump of the data in hexidecimal format:

H 48 
e 65
l 6c
l 6c
o 6f

It is odd though that all of the bytes are swapped (65 48 : e H)

If you're on a *nix system, you can use 'od -x', or 'man od' will tell you all the ways to get data from od :)

Pasteurization answered 6/4, 2011 at 19:52 Comment(6)
All of the bytes seem to be swapped, not just some of them.Burkle
This appears to be ASCII encoded text with the bytes swapped for some reason. See asciitable.comBurkle
@John: Little-endian has to do with numeric encoding not string encoding. en.wikipedia.org/wiki/EndiannessBurkle
Is there an equivalent binary Dump ?Helio
@Eric If this is the linux hexdump then the default output format (which the OP used) amounts to -x which displays the data as 16-bit integers. Hence endianness is an issue. OP should try with -c option to see if the switching goes away.Biocatalyst
@Biocatalyst - this is why I recommend od (besides that it's on 'every' *nix machine whereas hexdump may not be)Pasteurization
D
6

The text in the file new.txt is stored using ASCII encoding. Each letter is represented by a number, decimal: 32-127 hexidecimal: 20-7F. So the first three letters (H,e,l), are represented by the decimal numbers: 72,101,108 and the hexidecimal numbers: 48,65,6C

Hexdump by default takes each 16 bit word of the input file new.txt and outputs this word as a Hexidecimal number. Because it is operating on 16 bits, not 8 bits, you see the output in an unexpected order.

If you instead use xxd new.txt, you will see the output in the expected order.

Diencephalon answered 6/4, 2011 at 19:52 Comment(3)
As a pair ? 8bits should be represnted by Hex pair .Helio
8bits are represented by two hex digits. So the 4 in 48 is four bits and the 8 is the other four bitsDiencephalon
hd (which is a symlink to hexdump, and causes the -C switch to become default) will also produce the expected output.Astro

© 2022 - 2024 — McMap. All rights reserved.