单军华
2018-05-04 25f409185a53e5e7beb17518a684298d92d31b3f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//
//  NSString+HexToBytes.m
//  GoldRich
//
//  Created by WindShan on 2017/3/9.
//  Copyright © 2017年 WindShan. All rights reserved.
//
 
#import "NSString+HexToBytes.h"
 
 
 
@implementation NSString (HexToBytes)
 
-(NSData*) hexToBytes
{
    NSMutableData* data = [NSMutableData data];
    int idx;
    for (idx = 0; idx+2 <= self.length; idx+=2)
    {
        NSRange range = NSMakeRange(idx, 2);
        NSString* hexStr = [self substringWithRange:range];
        NSScanner* scanner = [NSScanner scannerWithString:hexStr];
        unsigned int intValue;
        [scanner scanHexInt:&intValue];
        [data appendBytes:&intValue length:1];
    }
    return data;
}
@end