[英]How to show content of NSData in bits?
I have NSData and I need to view its content in pure bits. 我有NSData,我需要以纯位查看其内容。 Tried NSLog [NSData description] but it returns NSString.
试过NSLog [NSData description]但它返回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
. ...在断点上停止后,在Local variables窗口中找到
bytes_memory
,右键单击它并选择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). 如果要打印到控制台位(格式为10011100),则需要将数据转换为相应的字符串表示形式( 此处为示例)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.