ios开发怎么计算nsdata的大小

 我来答
打伞鱼Aw
2016-04-10 · TA获得超过7266个赞
知道大有可为答主
回答量:7524
采纳率:90%
帮助的人:1577万
展开全部
NSData-> NSStringNSString *aString = [[NSString alloc] initWithData:adata encoding:NSUTF8StringEncoding];NSString->NSDataNSString *aString = @"1234abcd";NSData *aData = [aString dataUsingEncoding: NSUTF8StringEncoding];2.NSData 与 ByteNSData-> Byte数组NSString *testString = @"1234567890";NSData *testData = [testString dataUsingEncoding: NSUTF8StringEncoding];Byte *testByte = (Byte *)[testData bytes];for(int i=0;i<[testData length];i++)printf("testByte = %d\n",testByte[i]);Byte数组-> NSDataByte byte[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};NSData *adata = [[NSData alloc] initWithBytes:byte length:24];Byte数组->16进制数Byte *bytes = (Byte *)[aData bytes];NSString *hexStr=@"";for(int i=0;i<[encryData length];i++){NSString *newHexStr = [NSString stringWithFormat:@"%x",bytes[i]&0xff]; ///16进制数if([newHexStr length]==1)hexStr = [NSString stringWithFormat:@"%@0%@",hexStr,newHexStr];elsehexStr = [NSString stringWithFormat:@"%@%@",hexStr,newHexStr];}NSLog(@"bytes 的16进制数为:%@",hexStr);16进册弊制数->Byte数组///// 将16进制数据转化成Byte 数组NSString *hexString = @"3e435fab9c34891f"; //16进制字符串int j=0;Byte bytes[128]; ///3ds key的Byte 数组, 128位for(int i=0;i<[hexString length];i++){int int_ch; /// 两位16进制数转化后的10进制数unichar hex_char1 = [hexString characterAtIndex:i]; ////两位16进制数中的第一位(高位*16)int int_ch1;if(hex_char1 >= '0' && hex_char1 <='9')int_ch1 = (hex_char1-48)*16; //// 0 的Ascll - 48else if(hex_char1 >= 'A' && hex_char1 <='F')int_ch1 = (hex_char1-55)*16; //// A 的Ascll - 65elseint_ch1 = (hex_char1-87)*16; //// a 的Ascll - 97i++;unichar hex_char2 = [hexString characterAtIndex:i]; ///两位16进制数中的第二位(低位)int int_ch2;if(hex_char2 >棚销= '0' && hex_char2 <='9')int_ch2 = (hex_char2-48); //// 0 的Ascll - 48else if(hex_char1 >= 'A' && hex_char1 <='F')int_ch2 = hex_char2-55; //// A 的Ascll - 65elseint_ch2 = hex_char2-87; //// a 的Ascll - 97int_ch = int_ch1+int_ch2;NSLog(@"州和族int_ch=%d",int_ch);bytes[j] = int_ch; ///将转化后的数放入Byte数组里j++;}NSData *newData = [[NSData alloc] initWithBytes:bytes length:128];NSLog(@"newData=%@",newData);3. NSData 与 UIImageNSData->UIImageUIImage *aimage = [UIImage imageWithData: imageData];//例:从本地文件沙盒中取图片并转换为NSDataNSString *path = [[NSBundle mainBundle] bundlePath];NSString *name = [NSString stringWithFormat:@"ceshi.png"];NSString *finalPath = [path stringByAppendingPathComponent:name];NSData *imageData = [NSData dataWithContentsOfFile: finalPath];UIImage *aimage = [UIImage imageWithData: imageData];UIImage-> NSDataNSData *imageData = UIImagePNGRepresentation(aimae);
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式