Is there a way in Java to use unsigned numbers like in (My)SQL?
For example: I want to use an 8-bit variable (byte
) with a range like: 0
... 256
; instead of -128
... 127
.
No, Java doesn't have any unsigned primitive types apart from char
(which has values 0-65535, effectively). It's a pain (particularly for byte
), but that's the way it is.
Usually you either stick with the same size, and overflow into negatives for the "high" numbers, or use the wider type (e.g. short
for byte
) and cope with the extra memory requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With