-5

Normally Java int has range -2147483648...2147483647, so the max value is 2147483647, I don't want to use negative number. an int can have more than 4 billions of different values, can I use int range 2-4 billions? in eclipse, I use int a = 31474836471; I get compile error. how do I do?

user2166163
  • 57
  • 1
  • 3

3 Answers3

4

You've already asked this Question as part of another one.

The Answer is no, you cannot make the Java int type so that you have 4 billion values >= zero.

And asking the same Question again won't change the Answer.

You need to change your program to replace the "pk" type from int to long. You have no other alternatives, given you have stated that keys must be >= zero.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
2

No, in Java, all numbers are signed; there are no unsigned numbers. If you need a higher range of integers, then use long.

rgettman
  • 176,041
  • 30
  • 275
  • 357
1

You can't. The negative range is available for ints because the value is signed. Only so much information can be represented in the bits.

See this other question for some good differentiation between signed and unsigned numbers: Signed versus Unsigned Integers

Community
  • 1
  • 1
asteri
  • 11,402
  • 13
  • 60
  • 84