doujingke4981 2019-06-17 07:39
浏览 256
已采纳

Go和Javascript关于0xFFFFFFFF ^ 97有什么区别

I want to change Go code to Javascript code, but there is one mistake about result that is different between Go and Javascript. I want to change javascript's result to same as Go's result (0xFFFFFFFF ^ 97)

I try to debug it, and I recognize that 0xFFFFFFFF ^ 97 , in Go is 4294967198 but in javascript it is -98.

In Go:

number1 := 0xFFFFFFFF
number2 := 97
fmt.Print(number1 ^ number2) // 4294967198 

In Javascript:

var number1 = 0xFFFFFFFF
var number2 = 97
console.log(number1 ^ number2) // -98

0xFFFFFFFF ^ 97 is different result in Go and Javascript

  • 写回答

1条回答 默认 最新

  • doutao4480 2019-06-17 07:45
    关注

    In JavaScript, a bitwise operation (^ is bitwise XOR) converts the numbers signed 32-bit integer, then back to a double. So after the XOR operation is performed, the number is converted back to its default type - IEEE-754 double-precision binary number - and then the result is given.

    number -> 32-bit signed integer -> bitwise operation -> IEEE-754 double-precision binary number
    

    GoLang uses unsigned integers (GoLang spec), or, as pointed out by icza, int64 numbers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题