inline static nsdata* Encodebcd (NSString *value) {//nsstring *value = @ "123456"; Nsmutabledata *vdata = [[Nsmutabledata alloc] init];__uint8_t bytes[1] = {6}; [Vdata appendbytes:&bytes length:1]; Nsrange range;range.location = 0;range.length = 1;for (int i = 0; i < [value length];) {range.location = i; NSString *temp = [value substringwithrange:range];int _intvalue1 = [Temp intvalue];_intvalue1 = _intvalue1 << 4;rang E.location = i + 1;temp = [value substringwithrange:range];int _intvalue2 = [temp intvalue];int intvalue = _intvalue1 | _intvalue2;bytes[0] = intvalue; [Vdata appendbytes:&bytes Length:1];i + = 2;} Bytes[0] = 255; [Vdata appendbytes:&bytes length:1];bytes[0] = 255; [Vdata appendbytes:&bytes length:1];bytes[0] = 255; [Vdata appendbytes:&bytes length:1];bytes[0] = 255; [Vdata appendbytes:&bytes Length:1];return [Vdata autorelease];}
IOS BCD Encoding