Skip to content

Instantly share code, notes, and snippets.

@mikevoyt
Created August 19, 2016 04:39
Show Gist options
  • Save mikevoyt/7ef6d7edee5c8a0a0aa65ab039ac6fae to your computer and use it in GitHub Desktop.
Save mikevoyt/7ef6d7edee5c8a0a0aa65ab039ac6fae to your computer and use it in GitHub Desktop.
convert a string of hex characters into a string suitable for a C array initializer
package main
import (
"fmt"
"os"
)
func main() {
str := os.Args[1]
fmt.Print(" ")
for i := 0; i < len(str); {
fmt.Print("0x")
fmt.Printf("%c", str[i])
fmt.Printf("%c", str[i+1])
fmt.Print(", ")
i = i+2
if i % 16 == 0 {
fmt.Println()
fmt.Print(" ")
}
}
fmt.Println()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment