首页 > 其他分享 >Go - int overflow

Go - int overflow

时间:2024-02-14 20:22:57浏览次数:28  
标签:binary Int32 int fmt math Printf Go overflow MaxInt32

 

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

相关文章

  • Python 中 print 函数的用法
    在Python中,可以使用print函数来打印一个变量或者一个字符串:print("MynameisAlice")print(i)如果需要字符串格式化来打印一句话中包含变量的内容,有几种常用的方法:使用格式化字符串(f-string):在字符串前面加上字母"f",然后在字符串中使用大括号{}包裹变量名。示例代码如下:......
  • 如何为SharePoint Online站点扩容
    前言最近,因为项目已经上线,站点的文档和视频越来越多,默认给的50GB容量已经不够使用了,所以扩容迫在眉睫。正文1.进入Office365管理中心,找到Admin,如下图:2.找到SharePoint管理中心(如果没有需要点一下...showall),如下图:3.选中需要扩容的站点,在存储限......
  • Power Automate 获取超过5000条SharePoint Online 列表
    前言最近,碰到一个需求,用PowerAutomate获取大数据的SharePointOnline列表,默认的Action的设置是没办法获取到所有数据的,需要进行简单的配置。正文1.默认的Flow的配置,如下图:2.执行测试的结果,可以获取到100条数据,如下图:3.这里就需要设置一下TopCoun......
  • SharePoint Online 如何修改已存在站点的URL
    前言我们很多时候在创建SharePointOnline站点的时候,有需要改名字的情况。正文1.进入Office365管理中心,找到Admin,如下图:2.找到SharePoint管理中心(如果没有需要点一下...showall),如下图:3.选中想要修改的站点,点击Siteaddress下面的Edit,如下图:......
  • Go 之烧脑的接口
    基本定义Go官方对于接口的定义是一句话:An interfacetypeisdefinedasasetofmethodsignatures.翻译过来就是,一个接口定义了一组方法的集合。这和Java和PHP的接口类似,定义一组方法而不定义方法的具体实现。但是与Java和PHP迥然不同的地方在于Go不需要显式的声......
  • Go 100 mistakes - #16: Not using linters
    Alinterisanautomatictooltoanalyzecodeandcatcherrors. Tounderstandwhylintersareimportant,let’stakeoneconcreteexample.Inmistake#1,“Unintendedvariableshadowing,”wediscussedpotentialerrorsrelatedto variableshadowing.Using......
  • Go 100 mistakes - #15: Missing code documentation
    Documentationisanimportantaspectofcoding.ItsimplifieshowclientscanconsumeanAPIbutcanalsohelpinmaintainingaproject.InGo,weshouldfollowsome rulestomakeourcodeidiomatic.First,everyexportedelementmustbedocumented.Wheth......
  • Go语言精进之路读书笔记第26条——了解接口类型变量的内部表示
    接口是Go这门静态语言中唯一“动静兼备”的语言特性接口的静态特性接口类型变量具有静态类型,比如:vareerror中变量e的静态类型为error支持在编译阶段的类型检查:当一个接口类型变量被赋值时,编译器会检查右值的类型是否实现了该接口方法集合中的所有方法接口的动态特性接......
  • Go - Project structure
    TheGolanguagemaintainerhasnostrongconventionaboutstructuringaprojectin Go.However,onelayouthasemergedovertheyears:project-layout(https://github.com/golang-standards/project-layout).Ifourprojectissmallenough(onlyafewfiles),......
  • Go 100 mistakes - #11: Not using the functional options pattern
      Here,WithPortreturnsaclosure.Aclosureisananonymousfunctionthatreferences variablesfromoutsideitsbody;inthiscase,theportvariable.Theclosurerespectsthe Optiontypeandimplementstheport-validationlogic.Eachconfigfieldr......