Skip to content

Instantly share code, notes, and snippets.

@andig
Created January 5, 2021 16:48
Show Gist options
  • Save andig/150d8f4023a5f901c8c84c24ac8c2305 to your computer and use it in GitHub Desktop.
Save andig/150d8f4023a5f901c8c84c24ac8c2305 to your computer and use it in GitHub Desktop.
HexDump in Go
// hexDump
func hexDump(file io.Reader) {
dumpLimit := &io.LimitedReader{
R: file,
N: 512,
}
b, _ := ioutil.ReadAll(dumpLimit)
for len(b) > 32 {
slice := b[0:32]
str := strings.Builder{}
for _, c := range slice {
if c < 32 || c > 127 {
str.WriteString(".")
} else {
str.WriteByte(c)
}
}
fmt.Printf("% 0x %s\n", slice, str.String())
b = b[32:]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment