Why Long.toHexString(0xFFFFFFFF) returns ffffffffffffffff

前端 未结 4 710
無奈伤痛
無奈伤痛 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

    Of course, Long in java is 64-bits long! 0xFFFFFFFF means -1 as an int, when written in 64 bits, it's ffffffffffffffff.

    However, if the number were unsigned, the string would also be ffffffff [but there's no unsigned in java].

提交回复
热议问题