Why Long.toHexString(0xFFFFFFFF) returns ffffffffffffffff
问题 This is what I see in java, and it puzzles me. Long.toHexString(0xFFFFFFFF) returns ffffffffffffffff Similarly, 0xFFFFFFFF and Long.parseLong("FFFFFFFF", 16) are unequal. 回答1: 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) . 回答2: This: Long.toHexString(0xFFFFFFFF) is equivalent to: Long