Kalan's Blog

Kalan 頭像照片,在淡水拍攝,淺藍背景

四零二曜日電子報上線啦!訂閱訂起來

Software Engineer / Taiwanese / Life in Fukuoka
This blog supports RSS feed (all content), you can click RSS icon or setup through third-party service. If there are special styles such as code syntax in the technical article, it is still recommended to browse to the original website for the best experience.

Current Theme light

我會把一些不成文的筆記或是最近的生活雜感放在短筆記,如果有興趣的話可以來看看唷!

Please notice that currenly most of posts are translated by AI automatically and might contain lots of confusion. I'll gradually translate the post ASAP

xxd easy to use way record

xxd is a Linux tool that allows you to view binary files.

Why would you want to view binary files?

  • To compare the compiled program with what you intended
  • To inspect the contents of image or video files
  • Out of pure curiosity

Usage of xxd

xxd filename

This command will output the content of the file like this:

00000000: 4500 6d00 7000 7400 7900 0000 0000 0000  E.m.p.t.y.......
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................

It can be divided into three sections: the first one is the hex dump address, each line represents 16 characters (by default), the second section is the file content (in ASCII encoding), and the rightmost section displays the original values of the file. If there are any characters that cannot be displayed, a . will be shown.

xxd -r filename

This command can be used to restore the binary file to its original form.

Some combinations of techniques

  1. xxd filename | vim -: View a binary file using vim
  2. Open vim filename and inside vim, run :%!xxd -r to edit a binary file using vim
  3. xxd filename > dump.hex: Directly save the output to a file, which can be used with diff for comparison.

Prev

Rise of Creators - Programming

Next

Pips are still Important/idea still count

If you found this article helpful, please consider buy me a drink ☕️ It'll make my ordinary day shine✨

Buy me a coffee