Some of the offered solutions have limitations when it comes to the maximum allowed size of the numbers involved.
I have read what Luke wrote about using the fmt package but still i like to add an alternative solution to this page because i did not see anyone that offered this particular method, it's really only 3 lines and i am pretty sure that this solution will also be useful for some people who visit this page somewhere in the future.
package main
import(
"fmt"
"math/big"
)
func main() {
newbytes := []byte{159,127,208,150,211,126,210,192,227,247,240,207,201,36,190,239,79,252,235,104}
newkey := new(big.Int).SetBytes(newbytes)
fmt.Printf("%X \n", newkey)
}
Or if you just need to grab the string
package main
import(
"fmt"
"math/big"
)
func getHexString(bytesl []byte) (string) {
newkey := new(big.Int).SetBytes(bytesl)
base16str := fmt.Sprintf("%X",newkey)
return base16str
}
func main() {
newbytes := []byte{159,127,208,150,211,126,210,192,227,247,240,207,201,36,190,239,79,252,235,104}
hexstr := getHexString(newbytes)
fmt.Println(hexstr)
}
To be clear i'm not saying this is a good or the best method because that usually depends on the project environment so i just added this for completeness and demonstration purposes.
Here is yet another method using .Text(base)
package main
import(
"fmt"
"math/big"
)
func main() {
newbytes := []byte{159,127,208,150,211,126,210,192,227,247,240,207,201,36,190,239,79,252,235,104}
newkey := new(big.Int).SetBytes(newbytes)
// print by specifying base
// base2
fmt.Println(newkey.Text(2))
// base10
fmt.Println(newkey.Text(10))
//base16
fmt.Println(newkey.Text(16))
}