ZhangZhihui's Blog  

 

复制代码
func main() {
    fmt.Printf("math.MaxInt32:                         %d\n", math.MaxInt32)
    fmt.Printf("math.MinInt32:                        %d\n", math.MinInt32)
    var counter int32 = math.MaxInt32
    counter++
    fmt.Printf("math.MaxInt32 + 1 overflow:           %d\n", counter)
    fmt.Printf("math.MaxInt32 in binary:               %032b\n", math.MaxInt32)
    fmt.Printf("math.MaxInt32 + 1 overflow in binary: %032b\n", counter)
    var zero int32 = 0
    fmt.Printf("0 of Int32 in binary:                  %032b\n", zero)
    var minusZero int32 = -0
    fmt.Printf("-0 of Int32 in binary:                 %032b\n", minusZero)
    var one int32 = 1
    fmt.Printf("1 of Int32 in binary:                  %032b\n", one)
    var minusOne int32 = -1
    fmt.Printf("-1 of Int32 in binary:                 %032b\n", minusOne)
}
复制代码

 

复制代码
zzh@ZZHPC:/zdata/Github/ztest$ go run main.go
math.MaxInt32:                         2147483647
math.MinInt32:                        -2147483648
math.MaxInt32 + 1 overflow:           -2147483648
math.MaxInt32 in binary:               01111111111111111111111111111111
math.MaxInt32 + 1 overflow in binary: -10000000000000000000000000000000
0 of Int32 in binary:                  00000000000000000000000000000000
-0 of Int32 in binary:                 00000000000000000000000000000000
1 of Int32 in binary:                  00000000000000000000000000000001
-1 of Int32 in binary:                 -0000000000000000000000000000001
复制代码

 

 

 

 

 

Remember that Go provides a package to deal with large numbers: math/big. This might be an option if an int isn’t enough.

posted on   ZhangZhihuiAAA  阅读(28)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
 
点击右上角即可分享
微信分享提示