I have NSData and I need to view its content in pure bits. Tried NSLog [NSData description] but it returns NSString. Any suggestions?
use this for bytes
const char *byte = [data bytes];
NSLog(@"%s",byte);
this is for bits
const char *byte = [data bytes];
unsigned int length = [data length];
for (int i=0; i<length; i++) {
char n = byte[i];
char buffer[9];
buffer[8] = 0; //for null
int j = 8;
while(j > 0)
{
if(n & 0x01)
{
buffer[--j] = '1';
} else
{
buffer[--j] = '0';
}
n >>= 1;
}
printf("%s ",buffer);
You can look at these bytes in memory browser window:
void* bytes_memory = [yourData bytes]; // set breakpoint after this line
... after stopping on breakpoint find bytes_memory
in Local variables window, right click on it and choose View memory of *bytes_memory
.
If you want to print to console bits (in format 10011100), then you will need to convert data into corresponding string representation ( here is example).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.