The upper limit for any int
data type (excluding tinyint
), is always one less than the absolute value of the lower limit.
For example, the upper limit for an int
is 2,147,483,647 and ABS(lower limit) = 2,147,483,648.
Is there a reason why there is always one more negative int than positive int?
EDIT: Changed since question isn't directly related to DB's
The types you provided are signed integers. Let's see one byte(8-bit) example. With 1 byte you have 2^8
combinations which gives you 256 possible numbers to store.
Now you want to have the same number of positive and negative numbers (each group should have 128).
The point is 0
doesn't have +0
and -0
. There is only one 0
.
So you end up with range -128..-1..0..1..127
.
The same logic works for 16/32/64-bit
.
EDIT:
Why the range is -128 to 127
?
It depends on how you represent signed integer
: