由于hex是
Integer literal,因此您可以使用
See playground
原文链接:https://www.f2er.com/go/187034.htmlfmt.Sprintf()
以及%x或%X格式向
fmt package询问该整数的字符串表示形式.
See playground
i := 255 h := fmt.Sprintf("%x",i) fmt.Printf("Hex conv of '%d' is '%s'\n",i,h) h = fmt.Sprintf("%X",i) fmt.Printf("HEX conv of '%d' is '%s'\n",h)
输出:
Hex conv of '255' is 'ff' HEX conv of '255' is 'FF'