我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

为什么Go用^而不是〜来表示一元非位? [关闭]

Most programming languages use ~ to represent a unary bitwise-not operation. Go, by contrast, uses ^:

fmt.Println(^1)  // Prints -2

Why did the Go designers decide to break with convention here?

Because ^x is equivalent to m ^ x with m = "all bits set to 1" for unsigned x and m = -1 for signed x. Says so in the spec.

It's similar to how -x is 0 - x

近期文章

  • Postgres错误在数据库上运行查询:无法检测默认用户名
  • 我的迭代函数有什么问题
  • 我如何将reflect.New的返回值转换回原始类型
  • 执行:扩展未命名的类型,例如[] string
  • 无法使FindId工作(GO + MGO)
  • Beego-创建模型表格和ORM
  • 如何读取struct字段装饰器?
  • Go 1.5的自举编译器是否比用C语言编写的Go 1.4编译器慢?
  • Go中可以使用哪些指针?
  • Go Golang:合并排序堆栈溢出
  • 如何在st中解析来自stdin的无限json数组?
  • 我如何键入断言值是一个指针(指向字符串)?
  • 字节内置类型,不是uint8吗?
  • Golang上传整个目录并返回许多打开的文件
  • 如何按字母顺序对结构字段排序
  • Goroutines 8kb和Windows操作系统线程1 mb
  • 如何在Go中编写基准测试脚本以衡量运营/秒
  • 为什么用_空白标识符进行范围迭代会产生不同的值
  • 在Go中管理会话
  • 为什么以下golang程序会抛出运行时内存不足错误?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华