So I got an NSData object from network, like:
<93000000 026d6163 69640029 00000032 66353637 32636237 36363931 62393839 62626432 30323261 35333439 39333961 32643762 39353200 02696661 00210000 00373138 38616134 30313532 35346437 63396162 65326262 62326361 65653762 39000269 66760021 00000061 30346635 30373862 63383034 34343362 64636431 37653666 34326539 38306300 0a757569 640000>
Now I want to see what's the string using encoding:NSASCIIStringEncoding:
[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]
and I get:
"\xc2\x93\0\0\0\x02macid\0)\0\0\02f5672cb76691b989bbd2022a5349939a2d7b952\0\x02ifa\0!\0\0\07188aa4015254d7c9abe2bbb2caee7b9\0\x02ifv\0!\0\0\0a04f5078bc804443bdcd17e6f42e980c\0\nuuid\0\0"
Note: This string makes sense to me, because
a04f5078bc804443bdcd17e6f42e980c
is my device identifier get from
[UIDevice currentDevice].identifierForVendor]
Now I want to convert it back to NSData:
[str dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]
<13000000 026d6163 69640029 00000032 66353637 32636237 36363931 62393839 62626432 30323261 35333439 39333961 32643762 39353200 02696661 00210000 00373138 38616134 30313532 35346437 63396162 65326262 62326361 65653762 39000269 66760021 00000061 30346635 30373862 63383034 34343362 64636431 37653666 34326539 38306300 0a757569 640000>
As you can see, the first section is changed. How do I keep it the same?
0x93
is beyond the ASCII range, use a text encoding which also considers values > 0x7F
for example NSMacOSRomanStringEncoding