Søren's Blog

Random Ramblings

Previous Entry Share Next Entry
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


Log in

No account? Create an account