Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Format byte slice as hex digits
package main
import (
"fmt"
)
func dispByteSlice(slice []byte) {
for i, b := range slice {
if (i % 8) == 0 {
fmt.Printf("\n")
}
fmt.Printf("0x%02x, ", b)
}
fmt.Printf("\n")
}
func main() {
seed := []byte{
0, 50, 6, 244, 24, 199, 1, 25, 52, 88, 192,
19, 18, 12, 89, 6, 220, 18, 102, 58, 209,
82, 12, 62, 89, 110, 182, 9, 44, 20, 254, 22,
}
dispByteSlice(seed)
result := []byte{
84, 61, 124, 70, 203, 191, 91, 170, 188, 74, 176, 22, 97, 250, 169, 26,
105, 59, 39, 4, 246, 103, 227, 53, 133, 228, 214, 59, 165, 6, 158, 39,
}
dispByteSlice(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment