开发者

Access information from Byte Array using its index

开发者 https://www.devze.com 2023-03-29 03:01 出处:网络
I am usinga byte array to开发者_StackOverflow社区 store Nsdata of(4840 bytes) and nnow i have to access the data at index of byte array.here is my code .

I am using a byte array to开发者_StackOverflow社区 store Nsdata of(4840 bytes) and nnow i have to access the data at index of byte array.here is my code .

[Bufferdata appendBytes:&data length:len]; 
Byte *byteArray = (Byte *)[data bytes];

for(int i=0;i< sizeof(byteArray);i++)   
**NSLog(@"BYTES %@",[byteArray objectAtIndex:i])**;

but it is giving BAD ACCESS


The byteArray pointer you get back from [data bytes] is a pointer to raw bytes, not an object pointer. Since it doesn't point to an object, you can't use it to send messages like [byteArray objectAtIndex:i]. Instead, you should do something like:

for(int i=0;i< sizeof(byteArray);i++)   
    NSLog(@"BYTES %c", byteArray[i]);
0

精彩评论

暂无评论...
验证码 换一张
取 消