GO Program to to convert byte to string

How to convert the byte to string

Here we are explaining how to convert the byte to string in the Go program. We can use the built-in function fmt.println() to print anything and fmt.scanln() for reading the values. This function is defined under the fmt package and it helps to write standard output. In order to use these functions, we need to import the “fmt” package.


How to convert the byte to string in the GO Program

We are using fmt.println() function for printing the string to the output screen. Here we are showing how to convert the byte to string in the Go language. Here variable byteAr is holding the byte array to be converted. And variable str for holding the result string. Finally, the byte array is converted using string(byteAr) and print the result. Given below are the steps which are used in the Go program. 


STEP 1: Import the package fmt

STEP 2: Start function main()

STEP 3: Declare the byte array variable byteAr

STEP 4: Consider variable str for holding the result string

STEP 5: The byte array is converted using string(byteAr)

STEP 6: Finally print the variable str using fmt.Println()


GO Source Code

                                          package main
import (

func main() {

 byteAr := []byte{72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100}
 var str string
 str = string(byteAr)


Hello world