Home > Back-end >  Java how to convert the int negative to unsigned integer
Java how to convert the int negative to unsigned integer

Time:01-06

In the process of communication within the IC card to receive four bytes, converts it into a Java int type, because there is no Java unsigned integer types, sometimes there will be a negative number printed on the card is very ugly, only put it into a long, encountered such a problem, see a lot of similar posts, conventional methods:

Int I=9;//0 xfffffff7 decimal: 4294967287
Long l1=i& Integer. MAX_VALUE;//0 x7fff FFF7 decimal: 2147483639

In addition to the above this method just the sign bit, is not the original data into an unsigned number, misled many people, the correct method is:

Int I=9;
Long l1=long. The valueOf (Integer) toHexString (I). The toUpperCase (), 16);//0 xfffffff7 decimal: 4294967287

This method is the real unsigned integer value,

CodePudding user response:

Should the post rather than the post

CodePudding user response:

  • Related