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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, Java doesn’t have any unsigned primitive types apart from
char(which has values 0-65535, effectively). It’s a pain (particularly forbyte), 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.
shortforbyte) and cope with the extra memory requirements.