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
标签:binary,Int32,int,fmt,math,Printf,Go,overflow,MaxInt32 From: https://www.cnblogs.com/zhangzhihui/p/18015550