Søren Lund (slu) wrote,
Søren Lund

  • Location:
  • Mood:

Precision of Java integer types

I was having some problems with a numerical overflow, so I needed to know the precision of Java integer types. Could't find a simple overview, so I made one myself:

Precision of Java integer types
TypeBitsMin ... max values
Byte8-128 ... 127
Short16-32.768 ... 32.767
Integer32-2.147.483.648 ... 2.147.483.647
Long64-9.223.372.036.854.775.808 ... 9.223.372.036.854.775.807

The min/max values can be calculated like this: If n is the number of bits, then the min ... max interval is

-2^(n-1) ... 2^(n-1)-1
Tags: java
  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded