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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With