a = -2147483648 - a;编译器优化

发布于 2024-09-15 02:40:08 字数 354 浏览 3 评论 0原文

我正在尝试学习如何对软件进行逆向工程以及所有技巧来了解编译器优化之前代码的外观。

我多次发现类似的情况:

    if (a < 0)
      a = -2147483648 - a;

我最初认为这是一个 abs():下溢,因此您可以获得正值。但由于 a 是负数(参见 if),这相当于:

    if (a < 0)
      a = -2147483648 + abs(a);

这将是一个非常小的负数,并且根本不是 a 的绝对值。我缺少什么?

I'm trying to learn how to reverse engineer software and all the tricks to understand how the code looks like before the compiler optimizations.

I found something like this several times:

    if (a < 0)
      a = -2147483648 - a;

I originally thought it was an abs(): a underflows so you get the positive value. But since a is negative (see the if), this is equivalent to:

    if (a < 0)
      a = -2147483648 + abs(a);

Which will be a very small negative number, and not the absolute value of a at all. What am I missing?

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

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

发布评论

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

评论(4

-残月青衣踏尘吟 2024-09-22 02:40:08

它正在转换数字,以便第 31 位成为符号位,其余位 (0...30) 表示绝对大小。例如如果a = -5,那么运算后它就变成0x80000005。

It is converting the number so that bit 31 becomes a sign bit, and the rest bits (0...30) denotes the absolute magnitude. e.g. if a = -5, then after the operation it becomes 0x80000005.

你怎么敢 2024-09-22 02:40:08

它似乎从 2 的补码 转换为 符号幅度

It appears to be converting from 2's complement to sign-magnitude

つ可否回来 2024-09-22 02:40:08

我真诚地希望原始来源说的是 0x80000000 而不是 -2147483648 !十六进制数字至少给读者一个线索。小数是非常神秘的。

I sincerely hope that the original source said 0x80000000 and not -2147483648 ! The hex number at least gives the reader a clue. The decimal is very cryptic.

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