25. Hooking Java (un)signed integers in a nutshell
Signed values (or variables) such as signed integers or signed longs allow us to represent negative and positive numbers.
Unsigned values (or variables) such as unsigned integers or unsigned longs allow us to represent only positive numbers.
Signed and unsigned values (variables) of the same type share the same range. However, as you can see in the following figure, unsigned variables cover a larger magnitude number.
Figure 1.20: Signed and unsigned integers
The signed 32-bit integers range from –2,147,483,648 to 2,147,483,647 (around 4 billion values). Unsigned 32-bit integers range from 0 to 4,294,967,295 (also around 4 billion values).
So when we use signed integer variables, we can use 2 billion positive values, but when we use unsigned integer variables, we can use 4 billion positive values. The hatched part of the figure represents the extra 2 billion positive integer values.
Commonly, unsigned...