How to convert int to hexadecimal string in Go

3 Answers

0 votes
package main
 
import (
    "fmt"
    "strconv"
)
 
func main() {
    i := 255
    s := strconv.FormatInt(int64(i) , 16)

    fmt.Printf("Type : %T \nValue : %v\n", s, s) 
}
 
 
 
 
/*
run:
 
Type : string 
Value : ff
 
*/

 



answered May 26, 2020 by avibootz
0 votes
package main
 
import (
    "fmt"
)
 
func main() {
    i := 255

    s := fmt.Sprintf("%x", i)

    fmt.Printf("Type : %T \nValue : %v\n", s, s) 
}
 
 
 
 
/*
run:
 
Type : string 
Value : ff
 
*/

 



answered May 26, 2020 by avibootz
0 votes
package main
 
import (
    "fmt"
)
 
func main() {
    i := 65535

    s := fmt.Sprintf("%X", i)

    fmt.Printf("Type : %T \nValue : %v\n", s, s) 
}
 
 
 
 
/*
run:
 
Type : string 
Value : FFFF
 
*/

 



answered May 26, 2020 by avibootz

Related questions

1 answer 219 views
1 answer 191 views
1 answer 89 views
1 answer 79 views
1 answer 140 views
1 answer 244 views
1 answer 261 views
...