The non-problem of unsigned integers in Java
bitmath.blogspot.com·6h·
Discuss: Hacker News

The non-problem of unsigned integers in Java

Java famously has no unsigned integer types[1]. This is sometimes treated as a problem that needs a solution. Assuming that it is a problem, let’s see some solutions.

Solution 1: use a wider type

[...] Although it is possible to get around this problem using conversion code and larger data types, it makes using Java cumbersome for handling unsigned data. While a 32-bit signed integer may be used to hold a 16-bit unsigned value losslessly, and a 64-bit signed integer a 32-bit unsigned integer, there is no larger type to hold a 64-bit unsigned integer. In all cases, the memory consumed may double, and typically any logic relying on two’s complement overflow must be rewritten. [...]

[Wikipedia: Criticism of Java…

Similar Posts

Loading similar posts...