1 Star 0 Fork 0

encircles/learnGo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
demo13.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
encircles 提交于 2019-03-10 22:22 +08:00 . 190310 1
package main
import "fmt"
func main() {
// 重点1的示例
var srcInt = int16(-255)
// 请注意, 之所以要执行uint16(srcInt), 是因为只有这样才能得到全二进制的表示.
// 例如, fmt.Printf("%b", srcInt)将打印出"-11111111", 后者是负数符号再加上srcInt的绝对值的补码
// 而fmt.Printf("%b", uint16(srcInt))才会打印出srcInt原值的补码"1111111100000001".
fmt.Printf("The complement of srcInt: %b (%b)\n", uint16(srcInt), srcInt)
dstInt := int8(srcInt)
fmt.Printf("The complement of dstInt: %b (%b)\n", uint8(dstInt), dstInt)
fmt.Printf("The value of dstInt: %d\n", dstInt)
fmt.Println()
// 重点2的示例
fmt.Printf("The Replacement Character: %s\n", string(-1))
fmt.Printf("The Unicode codepoint of Replacement Character: %U\n", string(-1))
fmt.Println()
// 重点3的示例
srcStr := "你好"
fmt.Printf("The string: %q\n", srcStr)
fmt.Printf("The hex of %q: %x\n", srcStr, srcStr)
fmt.Printf("The byte slice of %q: %x\n", srcStr, []byte(srcStr))
fmt.Printf("The string: %q\n", string([]byte{'\xe4', '\xbd', '\xa0', '\xe5', '\xa5', '\xbd'}))
fmt.Printf("The rune slice of %q: %U\n", srcStr, []rune(srcStr))
fmt.Printf("The string: %q\n", string([]rune{'\u4F60', '\u597D'}))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/encircles/learnGo.git
git@gitee.com:encircles/learnGo.git
encircles
learnGo
learnGo
master

搜索帮助