ios - How can 2 NSData objects output the same HEX but be different when converted to char array? -
so have nsdata objects , method looks this:
+ (nsdata *)outputdata:(nsdata *)data andthisdata:(nsdata *)seconddata { char cdata[data.length]; [data getbytes:&cdata]; char cseconddata[seconddata.length]; [seconddata getbytes:&cseconddata]; nslog(@"nsdata: %@, %@", data, seconddata); nslog(@"hex: %x, %x",cdata,cseconddata); }
i'm getting output 2 separate nsdata objects same on face of it:
nsdata: <dc4945fa a76fa1eb 6c3de73e acabf71c>, <c7a75cfc 11697878 14b95c2b 8680b60b ed553909 d199c12b 6e66df1d 20dce6e5 46ef9cf6 0aefa4ee bf98b0d1 6579a311> hex: 5fbfe870, 5fbfe840 nsdata: <dc4945fa a76fa1eb 6c3de73e acabf71c>, <c7a75cfc 11697878 14b95c2b 8680b60b ed553909 d199c12b 6e66df1d 20dce6e5 46ef9cf6 0aefa4ee bf98b0d1 6579a311> hex: 5fbfe820, 5fbfe7f0
as can see nsdata output same, char
hex produce different (albeit similar). throwing off calculations , output of further calculations, can't see why different @ all.
so in situations occur? , how can remedy it?
many thanks. (if need more info please let me know).
you're not printing data in buffers. you're printing pointers addresses of 2 local arrays decay into. if print data, same:
nsmutablestring *hex = [nsmutablestring string], *secondhex = [nsmutablestring string]; (int = 0; < sizeof(cdata); i++) { [hex appendformat:@"%02x", cdata[i]]; [secondhex appendformat:@"%02x", cseconddata[i]]; } nslog(@"%@ %@", hex, secondhex);
Comments
Post a Comment