本文介绍了为什么Long.toHexString(0xFFFFFFFF)返回ffffffffffffffff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

这是我在Java中看到的,这使我感到困惑.

This is what I see in java, and it puzzles me.

Long.toHexString(0xFFFFFFFF)返回 ffffffffffffffff

类似地, 0xFFFFFFFF Long.parseLong("FFFFFFFF",16)不相等.

推荐答案

正如其他人所说, 0xFFFFFFFF 的值为 int -1 ,它被提升为 long .

As others have said, 0xFFFFFFFF evaluates to the int value -1, which is promoted to a long.

要获得预期的结果,请用 L 后缀限定常量,以指示应将其视为 long ,即 Long.toHexString(0xFFFFFFFFL).

To get the result you were expecting, qualify the constant with the L suffix to indicate it should be treated as a long, i.e. Long.toHexString(0xFFFFFFFFL).

这篇关于为什么Long.toHexString(0xFFFFFFFF)返回ffffffffffffffff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:04