使用NSdata 將Byte轉成Array

使用NSdata 將Bytet串列轉成 一個一個Byte的Array
 Byte byte[] = {208,0,0,255,255,3,0,2,4,0,0,0};
    NSData *adata = [[NSData alloc] initWithBytes:byte length:12];
   // NSMutableArray *Content=[[NSMutableArray alloc] init];
    NSLog(@"data =%@ length=%ld",adata,(unsigned long)[adata length]);
    
    NSMutableArray *ContentArray=[[NSMutableArray alloc] init];
 
    uint8_t byteArray[1];
    for (int i=0; i<[adata length]; i++) {
         [adata getBytes:&byteArray range:NSMakeRange(i,1)];
         NSData *gy=[[NSData alloc] initWithBytes:byteArray length:1];
        [ContentArray addObject:gy];
    }
   
    NSLog(@"%@",ContentArray);

輸出結果
Origin Data = length=12

Convert to  (
    ,
    <00>,
    <00>,
    ,
    ,
    <03>,
    <00>,
    <02>,
    <04>,
    <00>,
    <00>,
    <00>
) 



See also : http://www.exampledb.com/objective-c-nsdata-getbytes-get-byte-array.htm
張貼留言

Featured Post

安裝/更新 AZURE POWERSHELL

以下皆為powershell 安裝的指令 Install-Module Azure OR Install-Module Azure -AllowClobber 更新的指令 先看舊的版本 Get-Module AzureRM -ListAvaila...

Popular Posts