Created
January 5, 2021 16:48
-
-
Save andig/150d8f4023a5f901c8c84c24ac8c2305 to your computer and use it in GitHub Desktop.
HexDump in Go
This file contains hidden or 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
// 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