DevToolBox

Hex Dump 読み方ガイド - hexdump/xxd出力の見方

バイナリファイルが壊れているかもしれない、通信ログの中身を目視で確認したい――そんな時に 使うのが hex dump(hexダンプ)です。xxdhexdump -C を実行すると独特な3列のテキストが出力されますが、 構成さえ理解すれば読むのは難しくありません。この記事ではhex dumpの3列構成の読み方、 主要ツールの出力比較、ファイルシグネチャ判定への応用までを整理します。

A hex dump renders raw binary data as three aligned columns — byte offset, hex bytes, and an ASCII rendering — so you can inspect files that a text editor can't display. This guide explains how to read that layout, compares xxd/hexdump/PowerShell output, and shows how the same technique powers file-signature detection.

TL;DR

Hex Converter

テキストやHEX文字列をバイナリ表現に変換し、8bit二進数として並べて表示。貼り付けたhex dumpのバイト列を検証・再構成する用途にも使えます。ブラウザ完結・外部送信なし。

今すぐ試す →

1. hex dumpの3列構成 / The three-column layout

代表的な hexdump -C(BSD)や xxd の出力は、次の3つの要素で 1行を構成します。3列はすべて同じ16バイトを表しているだけで、 情報が3種類あるわけではありません。

00000000  89 50 4e 47 0d 0a 1a 0a  00 00 00 0d 49 48 44 52  |.PNG........IHDR|
│         │                        │                        │
オフセット  16進数バイト列(8バイトごとに区切り)              ASCII表現(印字不能= . )
内容補足
左端オフセット(16進数)ファイル先頭から何バイト目かを示す
中央16進数バイト列1バイト=16進数2桁。通常16バイト/行
右端ASCII表現印字可能な文字はそのまま、それ以外は.

All three columns describe the same 16 bytes: the offset says where they live in the file, the hex column is their raw value, and the ASCII column is a best-effort readable rendering — useful for spotting embedded strings inside otherwise-binary data.

2. ツール別の出力比較 / Comparing common tools

# xxd (Linux/macOS)
$ xxd -l 32 image.png
00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452  .PNG........IHDR
00000010: 0000 0064 0000 0064 0802 0000 00ff 80fe  ...d...d........

# hexdump -C (BSD/macOS/一部Linux)
$ hexdump -C -n 32 image.png
00000000  89 50 4e 47 0d 0a 1a 0a  00 00 00 0d 49 48 44 52  |.PNG........IHDR|
00000010  00 00 00 64 00 00 00 64  08 02 00 00 00 ff 80 fe  |...d...d........|

# od -A x -t x1z (POSIX標準、xxdが無い環境でも使える)
$ od -A x -t x1z -N 32 image.png
000000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52  >.PNG........IHDR<

# PowerShell (Windows)
PS> Format-Hex -Path image.png -Count 32

xxd はバイトを2バイトずつグループ化して表示するのに対し、hexdump -Cod は1バイトずつ空白区切りで表示するなど、 ツールによって細かいフォーマットは異なりますが、「オフセット + 16進数 + ASCII」という基本構造は共通です。

3. ファイルシグネチャ(マジックナンバー)の判定 / File signature detection

拡張子は簡単に書き換えられるため信頼できません。ファイル形式を確実に判定するには、先頭数バイトのマジックナンバーをhex dumpで確認し、既知のシグネチャと 比較します。上のPNGの例でも、先頭8バイト 89 50 4E 47 0D 0A 1A 0A が PNGシグネチャそのものです。

形式先頭バイト(HEX)ASCII表現
PNG89 50 4E 47.PNG
JPEGFF D8 FF...
GIF47 49 46 38GIF8
PDF25 50 44 46%PDF
ZIP / docx / xlsx50 4B 03 04PK..
ELF実行ファイル7F 45 4C 46.ELF
Windows実行ファイル(PE)4D 5AMZ

4. 実務での使いどころ / Where hex dumps are used

まとめ / Summary

hex dumpは「オフセット・16進数バイト・ASCII表現」という3つの視点から同じバイト列を 見比べる表示形式です。ツールごとにフォーマットの細部は違いますが、この基本構造さえ 覚えておけば xxd でも hexdump -C でも迷わず読めます。 ファイルシグネチャの判定に応用すれば、拡張子に頼らない確実な形式判定も可能です。

A hex dump is the same bytes shown three ways: where they are (offset), what they are (hex), and how they might read as text (ASCII). Once you internalize that structure, any tool's output — xxd, hexdump -C, od, or PowerShell's Format-Hex — becomes readable at a glance, and the same technique lets you identify file types by their magic number instead of trusting a possibly-renamed extension.

Hex Converter

HEX⇔Binaryモードで各バイトの8bit表現を一覧表示。貼り付けたhex dumpの一部を検証する用途にも便利です。

今すぐ試す →

関連ツール / Related tools

関連ガイド / Related guides