gpt4 book ai didi

java - 位运算符 - 精度

转载 作者:太空宇宙 更新时间:2023-11-04 07:51:00 31 4
gpt4 key购买 nike

我似乎一直困惑的三个问题:

  1. 为什么代码是 x & ~077比这行代码 x & 0177700 更好。是因为精度损失较小吗?

  2. 为什么此代码对于设置数字中的第 5 位不正确? num = num + 0x20是不是因为我们需要使用逻辑或, | ,而不是 +

  3. 为什么这个代码是 x & 0xFF比这行代码 (x << 24) >> 24 更好?正确的表达式可能会导致符号扩展,从而更改原始 int。从我所做的例子来看,我确信这是正确的。

最佳答案

1, why is this code x & ~077 better than this line of code x & 0177700.

因为在第二个中,您正在假设 x 的整数类型的长度

2, why is this code incorrect for setting bit 5 in a number? num = num + 0x20 Would it be because we need to use logical or, |, not the +?

是的!他们是不同的运营商。

关于java - 位运算符 - 精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14469662/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com