Objective C - NSNumber storing and retrieving longLongValue always prefixes with 0xFFFFFFFF -


i trying store file size in bytes nsnumber. reading file download size nsurlresponse , gives me long long value , create nsnumber object value , store it. when go retrieve value later, comes higher bytes set ffffffff.

for example, read in size 2196772870 bytes (0x82f01806) , store nsnumber. when back, -2098194426 bytes (0xffffffff82f01806). tried doing binary , 0x00000000ffffffff before storing value in nsnumber still comes negative. code below:

long long bytestotal = response.expectedcontentlength; nslog(@"bytestotal = %llx",bytestotal); [downloadinfo setfiletotalsize:[nsnumber numberwithint:bytestotal]]; //[downloadinfo setfiletotalsize:[nsnumber numberwithlonglong:bytestotal]]; long long filetotalsize = [[downloadinfo filetotalsize] longlongvalue];         nslog(@"filetotalsize = %llx",filetotalsize); 

output:

bytestotal = 82f01806 filetotalsize = ffffffff82f01806 

any suggestions?

edit: forgot setter downloadinfo object.

the problem line:

[downloadinfo setfiletotalsize:[nsnumber numberwithint:bytestotal]]; 

bytestotal not int, it's long long, should using numberwithlonglong:, not numberwithint:. change to:

[downloadinfo setfiletotalsize:[nsnumber numberwithlonglong:bytestotal]]; 

the conversion causing sign extended 64 bits, , number starting 8 appears negative number bit gets extended way thru upper long, causing ffffffff.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -