← All languages
Go function of the day
Random

strconv.FormatInt

Format an int64 as a string in a given base.

Description

strconv.FormatInt returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters a to z for digit values >= 10.

This function is useful for converting numbers to binary, octal, hexadecimal, or other base representations.

For base 10, strconv.Itoa is a convenient shorthand for strconv.FormatInt(int64(i), 10).

Arguments

NameDescriptionOptional
i The int64 value to format. No
base The numeric base (2 to 36). No

Example

fmt.Println(strconv.FormatInt(255, 16))  // ff
fmt.Println(strconv.FormatInt(255, 2))   // 11111111
fmt.Println(strconv.FormatInt(255, 8))   // 377

Reference