func main() {
var s byte = '?'
fmt.Println(s) //63
//输出 2/8/10 进制格式
fmt.Printf("%b,%o,%d\n", s, s, s) // 111111,77,63
// 以16进制输出字符串
fmt.Printf("%x\n", "hex this")
// 输出数值所表示的 Unicode 字符
fmt.Printf("%c\n", 63)
//输出数值所表示的 Unicode 字符(带单引号)。对于无法显示的字符,将输出其转义字符。
fmt.Printf("%q\n", 63)
//输出 Unicode 码点(例如 U+1234,等同于字符串 "U+%04X" 的显示结果)
fmt.Printf("%U\n", 63)
}
UTF-8编码规则
编码示例
func main() {
var s rune = '好'
fmt.Printf("%d\n",s) // 22909
buf := bytes.NewBufferString("hello")
fmt.Println(buf.Bytes()) // [104 101 108 108 111]
buf.WriteRune(s)
fmt.Println(buf.Bytes()) // [104 101 108 108 111 229 165 189]
}
好[229 165 189]好



将Unicode编码597D转化为UTF-8编码

可以看到utf-8编码是
E5A58D
,这是十六进制的,我们转为为10进制
11100101 10100101 10111101


