Atoi / Itoa — decimal shortcut
Atoi is Ascii-to-integer. Use when you have a plain base-10 int-sized value.
n, err := strconv.Atoi("42")
fmt.Println(n, err)
s := strconv.Itoa(-42)
fmt.Println(s)
Output
42 <nil>
-42
ParseInt / FormatInt — any base, any bit size
base=0 lets the prefix decide (0x=16, 0o=8, 0b=2, else 10). bitSize is the width to fit into.
n, _ := strconv.ParseInt("0xff", 0, 64) // 255
m, _ := strconv.ParseInt("-10", 10, 8) // -10 (fits int8)
_, err := strconv.ParseInt("300", 10, 8) // value out of range
s := strconv.FormatInt(255, 16) // "ff"
fmt.Println(n, m, err, s)
Output
255 -10 strconv.ParseInt: parsing "300": value out of range ff
ParseUint / FormatUint
u, _ := strconv.ParseUint("1010", 2, 64) // 10
fmt.Println(u, strconv.FormatUint(10, 2)) // "1010"