Reputation: 71
How to check if type is unsigned int or signed int in Java ? I used object.getExpressionType() to know type in Java, but it is showing or giving only long, int but not unsigned int or signed int. I am new to java can someone help me with this ? Thanks
Upvotes: 3
Views: 3189
Reputation: 41
As range of values of unsigned int is from 0 to 4294967295, you can implement it like this:
public static boolean isValid(long val) {
if ( (val < 0) || (val > 4294967295L))
return false;
else
return true; }
Upvotes: 2
Reputation: 28771
Surprisingly, Java has no unsigned integers. There is no way to exclude negative numbers using data type, only through program logic.
Upvotes: 11