[英]How to show content of NSData in bits?
我有NSData,我需要以純位查看其內容。 試過NSLog [NSData description]但它返回NSString。 有什么建議么?
將此用於字節
const char *byte = [data bytes];
NSLog(@"%s",byte);
這是為了比特
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);
您可以在內存瀏覽器窗口中查看這些字節:
void* bytes_memory = [yourData bytes]; // set breakpoint after this line
...在斷點上停止后,在Local variables窗口中找到bytes_memory
,右鍵單擊它並選擇View memory of *bytes_memory
。
如果要打印到控制台位(格式為10011100),則需要將數據轉換為相應的字符串表示形式( 此處為示例)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.