# Hex renderer in LaTeX

Is there a package to render binary files as hex in LaTeX. We've searched for it, but couldn't find any.

The package should provide some kind of command:

\lsthex{file.ext}


With file.ext a "binary" file (in this case the header of a .png file, but the content is here of course irrelevant).

Resulting in something like:

| 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 |
| 00 00 00 10 00 00 00 10 08 06 00 00 00 1F F3 FF |

• You should elaborate... Aug 24 '14 at 3:30
• Updated with an example. Better? Aug 24 '14 at 3:42
• Which OS are you using as I feel this is a job that is better suited outside of TeX and then the hex content can be rendered. Aug 24 '14 at 4:19
• Linux (Ubuntu 14.04) Aug 24 '14 at 5:44

Here is a version that works in MacOs (and should work on most Unix machines):

## Notes:

• You can replace the hexdump with different shell command. This method will show the output of that.
• This requires the -shell-escape option to allow for executing shell commands.

## Code:

\documentclass{article}
\usepackage{graphicx}
\usepackage{listings}

\newcommand{\ShowHexOutput}[2][\jobname.hex]{%
% #1 = temp file name
% #2 = input file name
%
\immediate\write18{hexdump -C #2 > ./#1}%
\lstinputlisting{./#1}%
}%

\lstset{basicstyle=\tiny\ttfamily}

\begin{document}
The image
\includegraphics[width=0.5\linewidth]{../images/EiffelWide.jpg}
in hex looks like:

\ShowHexOutput{../images/EiffelWide.jpg}
\end{document}