Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to easily convert to/from plain machine-readable HEX (without any paddings/offsets/character view) with xdd or hexdump?

I'm tired of digging of some special format strings (and finding out that it suddenly starts wrapping lines after N characters or skip lines) or writing Perl oneliners every time.

Why is it not as simple as base64/base64 -d?

share|improve this question
    
Because almost no one needs it. –  Ignacio Vazquez-Abrams May 5 '11 at 13:06
1  
base64 does wrap the output by default. –  grawity May 5 '11 at 13:09

2 Answers 2

up vote 1 down vote accepted
hexdump -e '"%x"'
xxd -p | tr -d '\n'

If you get tired of writing this every time, create an alias.

share|improve this answer
    
I'm tired of looking at man page and gettings confused either by necessity to compose hexdump's formt strings or by xxd's "postscript" thing. (Is this "postscript" something about printers or about letters?) –  Vi. May 5 '11 at 13:59
    
@Vi: It could be related to the inclusion of binary data in PostScript documents. –  grawity May 5 '11 at 14:03
1  
@Vi, think of -p as "plain". I surmise the Postscript comment is because the Postscript language allows for in-line data (typically images) encoded exactly this way. So Postscript programmers may use xxd to convert binary images into a convenient form for embedding in a Postscript file. –  RedGrittyBrick May 5 '11 at 14:05
$ xxd -p test.txt > test.hex
$ xxd -p -r test.hex test2.txt
$ diff test.txt test2.txt
$

Use alias or declare functions in your .profile to create mnemonics so you don't have to remember or dig about in man pages.

share|improve this answer
    
(was skipping "-p" option while reading man because of mysterious "postscript" thing) –  Vi. May 5 '11 at 13:57
    
Wrapped output. –  Vi. May 5 '11 at 13:59
1  
@Vi: I understand. Out of curiosity, what is the problem with wrapped output (i.e. a small percent of arguably superfluous LF chars)? –  RedGrittyBrick May 5 '11 at 14:01
    
It can be a problem if including hex in config files, like INIT=01303031313102 CMD1=41414141FF000000. –  Vi. May 5 '11 at 15:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.