To print a uint8 value as a string in Go, you can simply convert it to a string using the strconv.Itoa() function. Here’s an example:
package main
import (
"fmt"
"strconv"
)
func main() {
var num uint8 = 65
str := strconv.Itoa(int(num))
fmt.Println(str) // Output: 65
}
In this example, we first declare a uint8 variable named num
and set its value to 65. We then use the strconv.Itoa()
function to convert this value to a string and store it in a variable called str
. Finally, we print the value of str
using the fmt.Println()
function.
Note that if you try to convert a uint8 value that is outside of the ASCII range (0-127), the resulting string may not be printable or meaningful.