How can I convert from int to hex

前端 未结 6 2039
你的背包
你的背包 2020-12-14 15:53

I want to convert from int to hex in Golang. In strconv, there is a method that converts strings to hex. Is there a similar method to get a hex string from an int?

6条回答
  •  难免孤独
    2020-12-14 16:40

    i := 4357640193405743614
    h := fmt.Sprintf("%016x",i)
    fmt.Printf("Decimal: %d,\nHexa: %s", i, h)
    
    # Result
    Decimal..: 4357640193405743614,
    Hexa.....: 3c7972ab0ae9f1fe
    

    Playground: https://play.golang.org/p/ndlMyBdQjmT

提交回复
热议问题