ios打印二进制数据区

因为最近搞视频解码,经常需要打印数据查看,所以写了一个工具类

没有什么优化,仅仅为了查看二进制数据方便

////以二进制方式打印数组
///data 待打印二进制
/// length待打印长度
-(void)bytearrtostr:(Byte *)data length:(int)length
{
    char char_1 = '1',char_0 = '0';
    char *chars = malloc(length*8+1);
    chars[length*8] = '\n';
    for(int i=0;i>j)&0x01) == 1)
            {
                chars[i*8+j] = char_1;
            }else{
                chars[i*8+j] = char_0;
            }
        }
        char temp = 0;
        temp =  chars[i*8+0];chars[i*8+0] = chars[i*8+7];chars[i*8+7] = temp;
        temp =  chars[i*8+1];chars[i*8+1] = chars[i*8+6];chars[i*8+6] = temp;
        temp =  chars[i*8+2];chars[i*8+2] = chars[i*8+5];chars[i*8+5] = temp;
        temp =  chars[i*8+3];chars[i*8+3] = chars[i*8+4];chars[i*8+4] = temp;
    }
    NSString *string = [NSString stringWithCString:chars encoding:NSUTF8StringEncoding];
    NSLog(@"binnary string = %@",string);
}


你可能感兴趣的:(ios,ios,string,encoding,byte,优化,工具)