In Golang, you can convert an integer to its octal representation as a string using the strconv
package. Here's an example:
package main
import (
"fmt"
"strconv"
)
func main() {
num := 42
octal := strconv.FormatInt(int64(num), 8)
fmt.Println(octal) // Output: 52
}
In this example, we use the strconv.FormatInt()
function to convert the integer num
to its octal representation. The second argument 8
specifies the base to use for the conversion, which in this case is octal. The resulting octal representation is stored in the octal
variable and displayed using fmt.Println()
.