sarigehalli
sarigehalli

Reputation: 71

How can to check if type is unsigned int or signed int in Java ?

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

Answers (2)

Narek-P
Narek-P

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

Mudassir Hasan
Mudassir Hasan

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

Related Questions