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; range.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编码
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
ios编码解码 ios编码格式
命名规则一般原则清晰• 命名最好清晰又简洁,但是不能过于简洁而失去了清晰。
ios编码解码 移动开发 swift xcode 私有方法