Why Long.toHexString(0xFFFFFFFF) returns ffffffffffffffff

前端 未结 4 713
無奈伤痛
無奈伤痛 2021-01-14 00:30

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

Long.toHexString(0xFFFFFFFF) returns ffffffffffffffff

Similarly, 0xFFFFFFFF

4条回答
  •  渐次进展
    2021-01-14 01:02

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

    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).

提交回复
热议问题