如何在 C 中反转按位与 (&)?

发布于 2024-08-27 03:04:33 字数 253 浏览 8 评论 0原文

如何在 C 中反转按位与 (&)?

例如,我在 C 中有一个这样的操作:

((unsigned int)ptr & 0xff000000))

结果是 0xbf000000。我现在需要的是如何反转上面的过程,即通过运算结果确定ptr,当然还有0xff000000

有没有简单的方法可以用C实现这个?

How to reverse bitwise AND (&) in C?

For example I have an operation in C like this:

((unsigned int)ptr & 0xff000000))

The result is 0xbf000000. What I need at this moment is how to reverse the above, i.e. determine ptr by using the result from the operation and of course 0xff000000.

Is there any simple way to implement this in C?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

心如狂蝶 2024-09-03 03:04:33

按位 & 不能反转:

0 & 1 = 0
0 & 0 = 0

Bitwise & can't be reversed:

0 & 1 = 0
0 & 0 = 0
饮湿 2024-09-03 03:04:33

你不能这样做,因为你已经丢弃了信息(即位) - 你无法从任何地方取回信息。

请注意,AND (&) 和 OR (|) 都是破坏性的。唯一可逆的布尔运算是 XOR (^) 和 NOT (~)。

You can't do that because you have thrown away information (i.e. bits) - you can't get information back from nowhere.

Note that both AND (&) and OR (|) are destructive. The only Boolean operations that are reversible are XOR (^) and NOT (~).

爱,才寂寞 2024-09-03 03:04:33

不可能的。按位与0xff000000 是有损操作。您将永久丢失低 24 位。

Impossible. Bitwise & of 0xff000000 is a lossy operation. You lose the lower 24-bits permanently.

三月梨花 2024-09-03 03:04:33

您只能反转异或,因为它是非破坏性的。

OR 和 AND 都是破坏性的。

You can only reverse XOR, as it's non-destructive.

Both OR and AND are destructive.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文