Skip to content

Instantly share code, notes, and snippets.

@guesslin
Last active August 28, 2019 01:09
Show Gist options
  • Save guesslin/ee38abfac7284843f04c02d1a0c9763f to your computer and use it in GitHub Desktop.
Save guesslin/ee38abfac7284843f04c02d1a0c9763f to your computer and use it in GitHub Desktop.
packet main
import "fmt"
func HexPacket(raw []byte) {
idx := 0
for ; idx < len(raw)-16; idx += 16 {
fmt.Printf("%04X: ", idx)
for i := 0; i < 16; i++ {
fmt.Printf("%02X ", raw[idx+i])
if (i+1)%4 == 0 {
fmt.Printf(" ")
}
}
fmt.Printf("\n")
}
if idx < len(raw) {
fmt.Printf("%04X: ", idx)
for i := 0; i < len(raw)-idx; i++ {
fmt.Printf("%02X ", raw[idx+i])
if (i+1)%4 == 0 {
fmt.Printf(" ")
}
}
fmt.Printf("\n")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment