I’m getting weird NSString value after performing a conversion. For example, I have one byte with value 2 (00000010) that is stored in response. I tried both NSString initWithData and initWithBytes but both return weird symbol (upside down question mark). Here’s my code:
NSString *command1 = [[NSString alloc] initWithData:response encoding:NSASCIIStringEncoding];
NSString *command2 = [[NSString alloc] initWithBytes:[response bytes] length:[response length] encoding:NSASCIIStringEncoding];
NSLog(@"command1: %@", command1);
NSLog(@"command2: %@", command2);
Also tried NSUTF8StringEncoding but NSASCIIStringEncoding is correct one because data comes encoded one byte per symbol.
From what I am reading, this is what you want:
It just simply converts each byte to it’s integer representation and concatenates that into a string.