Last active
December 22, 2017 19:01
-
-
Save yesmar/241cb0d2bb06edbdb9d3580a3685c31e to your computer and use it in GitHub Desktop.
No frills hex dump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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