Created
August 19, 2016 04:39
-
-
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
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
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