varun257
varun257

Reputation: 296

Getting unsigned int from json object in java

How can i get unsigned int number in java from json object. It truncates the value since its not supported. Is there anyway to get it or should i just go for long??

data.getInt("some key");

Here data is the json object. I have the field as unsigned integer in the database.

Upvotes: 0

Views: 770

Answers (1)

ben
ben

Reputation: 71

int i=data.getInt("some key");


long j=0x00000000ffffffffL&i;

j is what you need;The problem is it is negative ,when the highest bit of int is 1.For example,0xffffffff is -1;0x0ffffffff is positive,but it is out of range of int.You can extend it to long and set hight 32 bit all to 0.

Upvotes: 1

Related Questions