Skip to content

Instantly share code, notes, and snippets.

@wilkice
Created December 24, 2021 07:30
Show Gist options
  • Save wilkice/dd10a2dbcde4805d5993578d4c56ce8e to your computer and use it in GitHub Desktop.
Save wilkice/dd10a2dbcde4805d5993578d4c56ce8e to your computer and use it in GitHub Desktop.
[hex, int, string]
package main
import (
"fmt"
"strconv"
"encoding/hex"
)
func main() {
// "A"
// ascii: 65
// hex: 41
// num string to int
s := "65"
fmt.Println(strconv.Atoi(s)) // 65
// int to num string
b := 65
fmt.Println(strconv.Itoa(b)) // "65"
// hex string to int
y := "41"
e, err := strconv.ParseInt(y, 16, 64)
fmt.Println(e, err) // 65 <nil>
// int to ascii string
fmt.Println(string(65)) // "A"
// hex Bytes to hex string:
fmt.Println(hex.EncodeToString([]byte{65, 66})) // "4142"
// hex string to int
fmt.Println(hex.DecodeString("4142")) // [65 66]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment