0

How does java calculate this?

int number = (int) Long.parseLong("F9DFF755", 16);

Long.parseLong("F9DFF755", 16); == 4192204629 (too big to be stored by an int)
Casted to int : -102762667

How does java force a long to fit into an int?

grepsedawk
  • 3,324
  • 2
  • 26
  • 49

1 Answers1

8

Casting a long to an int simply consist in keeping the last 32 bits of the long, and ignoring the first 32 bits.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255