Skip to content

Instantly share code, notes, and snippets.

@ElfSundae
Forked from dstebila/bin2hex.sh
Created December 28, 2019 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElfSundae/f3055986f3dfc0bcfb25f0085aa4972f to your computer and use it in GitHub Desktop.
Save ElfSundae/f3055986f3dfc0bcfb25f0085aa4972f to your computer and use it in GitHub Desktop.
Shell script to convert binary to hex
#!/bin/bash
# Read either the first argument or from stdin (http://stackoverflow.com/questions/6980090/bash-read-from-file-or-stdin)
cat "${1:-/dev/stdin}" | \
# Convert binary to hex using xxd in plain hexdump style
xxd -ps | \
# Put spaces between each pair of hex characters
sed -E 's/(..)/\1 /g' | \
# Merge lines
tr -d '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment