Skip to content

Instantly share code, notes, and snippets.

@yesmar
Last active December 22, 2017 19:01
Show Gist options
  • Save yesmar/241cb0d2bb06edbdb9d3580a3685c31e to your computer and use it in GitHub Desktop.
Save yesmar/241cb0d2bb06edbdb9d3580a3685c31e to your computer and use it in GitHub Desktop.
No frills hex dump
package main
import (
"fmt"
)
// HexDump the specified byte slice.
func HexDump(bs []byte, width int) {
for i, v := range bs {
fmt.Printf("%02x ", v)
// Drop a newline every 20 bytes.
if i > 0 && i%(width-1) == 0 {
fmt.Printf("\n")
}
}
fmt.Printf("\n")
}
func main() {
s := "pan galactic gargle blaster"
HexDump([]byte(s), 20)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment