0

继续我之前的问题 为什么我不能从 long 派生?

我发现了一个有趣的问题。

第一步:

4294967296 & 0xFFFFFFFF00000000

结果:4294967296。

第二步。

4294967296 & 0x00000000FFFFFFFF

结果:0

啊哈,所以在这里我假设 4294967296 == 0xFFFFFFFF

让我们检查

(long)0x00000000FFFFFFFF

结果:4294967295。失败。

让我们仔细检查一下

4294967296 >> 32

结果: 1. 失败。

唯一的解释是,因为我使用 long ,其中一些位保留用于符号。在 CI 中将使用 unsigned long。你们觉得怎么样?

4

3 回答 3

5
4294967296 & 0xFFFFFFFF00000000 = 4294967296

这表明值 4294967296 在低 32 位中没有设置任何位。事实上,4294967296 是 0x100000000,所以这是真的。

4294967296 >> 32 = 1

再次,一致。

换句话说,您认为 4294967296 是 0xFFFFFFFF 的结论是错误的,因此剩余的检查将不支持这一点。

于 2009-11-23T14:58:37.687 回答
3

Um... I'm not sure why you came to the conclusions you did but 4294967296 is 0x100000000. To write out the bitwise AND's in easily readable hex...

0x0000000100000000 &
0x00000000FFFFFFFF =
0x0000000000000000

0x0000000100000000 &
0xFFFFFFFF00000000 =
0x0000000100000000

Both of those make perfect sense. Perhaps you're misunderstanding a bitwise AND... it maps the bits that are the same in both. Your comments seem more appropriate to a bitwise XOR than a bitwise AND (Which is not the operation you're using)...

于 2009-11-23T15:03:29.970 回答
1

我认为您无法理解按位and运算。按位and将返回两者中设置的位。如果两者相同的话

(4294967296 & 0xFFFFFFFF00000000) == 4294967296

(4294967296 & 0xFFFFFFFF00000000) == 0xFFFFFFFF00000000

两者都会成立,但他们显然不成立。

于 2009-11-23T15:01:25.780 回答