Skip to content

Instantly share code, notes, and snippets.

@nmarley
Created September 27, 2019 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmarley/d988ea7e9f9ada376fa2567b98b702de to your computer and use it in GitHub Desktop.
Save nmarley/d988ea7e9f9ada376fa2567b98b702de to your computer and use it in GitHub Desktop.
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