Convert hex data string to NSData in Objective C (cocoa)

后端 未结 9 1334
栀梦
栀梦 2020-12-03 11:55

fairly new iPhone developer here. Building an app to send RS232 commands to a device expecting them over a TCP/IP socket connection. I\'ve got the comms part down, and can s

9条回答
  •  青春惊慌失措
    2020-12-03 12:33

    Another way to do it.

    -(NSData *) dataFromHexString:(NSString *) hexstr
    {
        NSMutableData *data = [[NSMutableData alloc] init];
        NSString *inputStr = [hexstr uppercaseString];
    
        NSString *hexChars = @"0123456789ABCDEF";
    
        Byte b1,b2;
        b1 = 255;
        b2 = 255;
        for (int i=0; i

提交回复
热议问题